Sign in to follow this  

C# & Windows Forms

Recommended Posts, I'm trying to create an app that has a nice little menu bar, and one of the options brings up a preferences dialog where you can set....settings. Problem is, how do I make clicking this option bring up a new windows form? I'm assuming I want a new windows form with all the proper controls, set up so that when I hit "Apply" it saves the changes (in my case to a txt file for simplicity) and closes the form. How might I do this? Am I using the right method, or should I be using a usercontrol? I'm a little lost here. Thanks! RA

Share this post

Link to post
Share on other sites
A new form should be just fine. In the handler for the menu option, you can create an instance of the new form and then call Show() or ShowDialog() on it. Just doing Show() would require a more detailed design, but it would free your users from the evil we all call "modal dialog boxes." The new form you create would need to have some sort of reference back to the where you're storing the settings the user will be changing on it though.

That's a pretty high-level explanation. Look into those two functions... try calling them on a form to get a feel for how they work. If you have more questions, post 'em!

Happy coding!

Share this post

Link to post
Share on other sites
Hello Rampantandroid,

Do you have the 'pop-up' dialog already defined (did you made a separated form with all the controls in it), or do only have the main form?

If it is the first situation, you can create and show this very simple:

// MyApplication is your own namespace
// SettingsDialog is the form class you defined, the Dialog
System.Windows.Forms.Form NewDialog = new MyApplication.SettingsDialog(...);
NewDialog.Show(); // Thats all

if it is the latter situation you need to add the controls at runtime

System.Windows.Forms.Form NewDialog = new System.Windows.Forms.Form();

Form.Controls.Add(new Button("Apply"));
Form.Controls.Add(new CheckBox("God mode: "));
// ...


Hope this helps you in on the way, if not feel free to ask :D



Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this