![]() |
Showing and Hiding Multiple forms
I have been try this for a while now (about a week) and did some research and eventually came up with the following code.
[php] using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; namespace multiple_windows { public partial class MainForm { [STAThread] public static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } public MainForm() { InitializeComponent(); } void MainFormLoad(object sender, System.EventArgs e) { } void Button1Click(object sender, System.EventArgs e) { multiple_windows.MainForm.ActiveForm.Hide(); multiple_windows.Form1.ActiveForm.Show(); } } } [/php] when i compile it... it works find but if i click the button it gives me this error. :
Exception System.NullReferenceException was thrown in debuggee:I know i'm missing something but i just don't see it. Is anyone able to help me find out whats missing? |
How about showing the other half of the partial class MainForm. Then we might have a better chance of finding and fixing the problem :)
|
Sorry. What I posted for MainForm is everything that is in it. I have another form 'Form1' that has its own code... is that what you mean?
|
What he means is the class MainForm is split between two files. That is why the keyword partial is used.
What the forms designer does in VS is split the form class in two. One half is for event handlers etc and t'other is for the forms fields(controls etc) and the InitializeComponent() method which is called by the constructor. All the properties you set on your forms and controls would be in this method and being able to see it will help work out what is going wrong. Sadly I have not used Visual C# in ages and cant recal how to bring up the other half of the class. Maybe someone else can explain how to get to it but i dont think its too hard to bring up. |
well i don't know if understand it right,here wht i understand :
when you press this button you want the main form to hide and form1 to show. if so then :
void Button1Click(object sender, System.EventArgs e)if it's not what you want then goodluck figuring it out |
| All times are GMT -5. The time now is 12:55 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC