Where to start?
-
Ok, I've got this project which I've been developing for about 9 months now as a .NET web application. I was told today that we're switching gears and it's going to be a Windows app instead. Ok, slight problem. I know exactly two things about Windows app development, Jack and S**t. And guess what, Jack's just left town. So I throw myself upon the mercy of the gurus. Can anybody point me to a good tutorial on WinForms that talks about a multi-form application and using menus to switch between active forms. The only WinForm app ever developed by anyone at work was a small demo app that had two forms with a button on form 1 to hide form 1 and show form 2, then a button on form 2 to hide form 2 and show form 1. I've tried googling for some tutorials and I'm coming up with nothing helpful. Anyone got any ideas?
-
Ok, I've got this project which I've been developing for about 9 months now as a .NET web application. I was told today that we're switching gears and it's going to be a Windows app instead. Ok, slight problem. I know exactly two things about Windows app development, Jack and S**t. And guess what, Jack's just left town. So I throw myself upon the mercy of the gurus. Can anybody point me to a good tutorial on WinForms that talks about a multi-form application and using menus to switch between active forms. The only WinForm app ever developed by anyone at work was a small demo app that had two forms with a button on form 1 to hide form 1 and show form 2, then a button on form 2 to hide form 2 and show form 1. I've tried googling for some tutorials and I'm coming up with nothing helpful. Anyone got any ideas?
Well, the main thing is, you just show a form by creating an instance of it and then calling ShowDialog or Show, depending on if you want it to be modal or not. If your main form switches between forms, I'd create them as controls, put them all on the form, and swap which one is visible.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Well, the main thing is, you just show a form by creating an instance of it and then calling ShowDialog or Show, depending on if you want it to be modal or not. If your main form switches between forms, I'd create them as controls, put them all on the form, and swap which one is visible.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
Christian Graus wrote:
create them as controls, put them all on the form, and swap which one is visible
That's what the demo app I've got does. But this app is going to be a few hundred forms. It's going to be a replacement for four individual MS Access applications and we're rolling them all into one app as the departments that used them have been consolidated into one. I was hoping to be able to create a menu with some sort of method for showing/hiding controls and when the user clicks on a menu item that control shows and the currently visible one hides. Does that sound reasonable?
-
Christian Graus wrote:
create them as controls, put them all on the form, and swap which one is visible
That's what the demo app I've got does. But this app is going to be a few hundred forms. It's going to be a replacement for four individual MS Access applications and we're rolling them all into one app as the departments that used them have been consolidated into one. I was hoping to be able to create a menu with some sort of method for showing/hiding controls and when the user clicks on a menu item that control shows and the currently visible one hides. Does that sound reasonable?
FyreWyrm wrote:
Does that sound reasonable?
Yeah, the way I'd do that is, have an enum of forms, store the enum for the form you want in the tag, then write a method that you call which hides all forms, then shows the one specified by the enum value. So, you have one menu click event, which reads the tag, then turns it into an enum and calls one method that is always responsible for setting the visible form. You can just iterate over the controls collection to hide your controls. You could even have the controls that are the forms have the same tag values so one function checks each controls tag and works out which one to show, no switch or anything needed.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
FyreWyrm wrote:
Does that sound reasonable?
Yeah, the way I'd do that is, have an enum of forms, store the enum for the form you want in the tag, then write a method that you call which hides all forms, then shows the one specified by the enum value. So, you have one menu click event, which reads the tag, then turns it into an enum and calls one method that is always responsible for setting the visible form. You can just iterate over the controls collection to hide your controls. You could even have the controls that are the forms have the same tag values so one function checks each controls tag and works out which one to show, no switch or anything needed.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Thanks Christian. I appreciate your help. I'm going to look into this more when I get to work tomorrow.
Cool - just post again if you get stuck.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Ok, I've got this project which I've been developing for about 9 months now as a .NET web application. I was told today that we're switching gears and it's going to be a Windows app instead. Ok, slight problem. I know exactly two things about Windows app development, Jack and S**t. And guess what, Jack's just left town. So I throw myself upon the mercy of the gurus. Can anybody point me to a good tutorial on WinForms that talks about a multi-form application and using menus to switch between active forms. The only WinForm app ever developed by anyone at work was a small demo app that had two forms with a button on form 1 to hide form 1 and show form 2, then a button on form 2 to hide form 2 and show form 1. I've tried googling for some tutorials and I'm coming up with nothing helpful. Anyone got any ideas?
Actually what you need is a WinForm with one main form and every form will be shown in the main form, one at a time, right? You can create the forms as per normal, and instead of calling Show(), do the following instead. The form will be shown in the body of main form.
Form2 form = new Form2();
form.FormBorderStyle = FormBorderStyle.None;
form.TopLevel = false;
mainForm.Controls.Add(form);
form.Show(); -
Actually what you need is a WinForm with one main form and every form will be shown in the main form, one at a time, right? You can create the forms as per normal, and instead of calling Show(), do the following instead. The form will be shown in the body of main form.
Form2 form = new Form2();
form.FormBorderStyle = FormBorderStyle.None;
form.TopLevel = false;
mainForm.Controls.Add(form);
form.Show();Cool - so that basically adds the forms as controls, it's another path to what I was saying ?
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Cool - so that basically adds the forms as controls, it's another path to what I was saying ?
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )