Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 13th, 2006, 1:29 PM   #1
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 579
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
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:
Object reference not set to an instance of an object.

Button1Click() - c:\Documents and Settings\David\My Documents\SharpDevelop Projects\multiple windows\multiple windows\MainForm.cs:31,4
OnClick()
OnClick()
OnMouseUp()
WmMouseUp()
WndProc()
WndProc()
WndProc()
OnMessage()
WndProc()
DebuggableCallback()
System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop()
RunMessageLoopInner()
RunMessageLoop()
Run()
Main() - c:\Documents and Settings\David\My Documents\SharpDevelop Projects\multiple windows\multiple windows\MainForm.cs:15,4

I know i'm missing something but i just don't see it. Is anyone able to help me find out whats missing?
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Old Sep 13th, 2006, 1:45 PM   #2
Anonymous Coward
Newbie
 
Join Date: Sep 2006
Posts: 11
Rep Power: 0 Anonymous Coward is on a distinguished road
How about showing the other half of the partial class MainForm. Then we might have a better chance of finding and fixing the problem
Anonymous Coward is offline   Reply With Quote
Old Sep 13th, 2006, 1:56 PM   #3
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 579
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
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?
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Old Sep 13th, 2006, 2:12 PM   #4
_James_
Newbie
 
Join Date: Sep 2006
Location: UK
Posts: 20
Rep Power: 0 _James_ is an unknown quantity at this point
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.
_James_ is offline   Reply With Quote
Old Sep 13th, 2006, 4:24 PM   #5
Samuaijack
Programmer
 
Samuaijack's Avatar
 
Join Date: Jul 2006
Location: using Earth.Africa.Egypt.Cairo;
Posts: 73
Rep Power: 3 Samuaijack is on a distinguished road
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)
{
    Form1 frm1 = new Form1(); 
    this.Hide();
    frm1.Show();
}

if it's not what you want then goodluck figuring it out
Samuaijack is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:11 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC