I am building an application using the .NET CF Framework and I had a situation where I wanted to present the user with a custom Dialog Box.
My solution was to create a simple Form with radio buttons for choices and a button. When clicked the button saves the selected radio button value to a public property and closes the Form.
The UserControl, after calling ShowDialog on the Form, inspects the public property to learn what option the user picked.
This worked perfectly. I’m just wondering if this is bad practice and if i’m going to get myself in trouble, somehow by doing this. It seems odd that a UserControl should be creating a Form.
Is there a better way to go about creating a custom Dialog Box from within a UserControl?
Absolutely nothing wrong with that. It is essentially the same as calling
MessageBox.Show()from a UserControl.And yes, accessing the result as a public property is the way to do it.
I’m guessing that this will be a dialog? You should consider using the DialogResult if you have multiple ‘exit’ options – OK, Cancel, etc.