I have this really (REALLY) stupid problem: how do I make an input dialog in c# .NET? Just a small form, with a textbox and an "ok"-button.
The obvious way is to do it like this:
InputDialog MyInputDialog = new InputDialog();
MyInputDialog.ShowDialog();
string s = MyInputDialog.MyInput.Text;
While that works in .NET when running on Windows, (I think) that is because Windows has a lax garbage collector. When run on a Pocket PC (Windows .NET Compact Framework), I get a NullReferenceException, as I should.
Edit: (Type)this.Parent or (Type)this.Owner both give a NullReferenceException as well.
And the modal result is a set: { "Yes", "No", "Cancel" } etc. You cannot have a form return any other value.
So, how do I do it? The only solutions I can think of are:
- Use event handlers (make a new handler class, and have the parent add a message handler to the client form)
- Start the input dialog as a new thread and use the tread synchronization mechanism
- Remove all the logic from the forms and start them all from a global unit
- Use a temp file or a static class to hold the value
But there has to be a simple solution, right? An existing class that already does this. Or another solution that allows me to write a library class that simply returns me a value from anywhere?
The obvious way is to do it like this:
InputDialog MyInputDialog = new InputDialog();
MyInputDialog.ShowDialog();
string s = MyInputDialog.MyInput.Text;
While that works in .NET when running on Windows, (I think) that is because Windows has a lax garbage collector. When run on a Pocket PC (Windows .NET Compact Framework), I get a NullReferenceException, as I should.
Edit: (Type)this.Parent or (Type)this.Owner both give a NullReferenceException as well.
And the modal result is a set: { "Yes", "No", "Cancel" } etc. You cannot have a form return any other value.
So, how do I do it? The only solutions I can think of are:
- Use event handlers (make a new handler class, and have the parent add a message handler to the client form)
- Start the input dialog as a new thread and use the tread synchronization mechanism
- Remove all the logic from the forms and start them all from a global unit
- Use a temp file or a static class to hold the value
But there has to be a simple solution, right? An existing class that already does this. Or another solution that allows me to write a library class that simply returns me a value from anywhere?
Last edited by a moderator: