Changing property of an object from a modal form.

R

rhaazy

using C# VS2003

private void frmMDIMain_Load(object sender, System.EventArgs e)
{
Form frmLogin = new frmLogin();
frmLogin.ShowDialog();

}

private void frmLogin_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
frmMDIMain.panel5.Visible = true;
frmMDIMain.button1.Visible = true;
frmMDIMain.panel6.Visible = true;
frmMDIMain.dataGrid1.Visible = true;
}

How do I make the code in frmLogin_Closing work? I made the objects
public but the compiler still tells me I have to create an object
reference... There must be something I'm missing any help would be
great.
 
B

Brian Richards

You need to do something like:

private void frmMDIMain_Load(object sender, System.EventArgs e)
{
Form frmLogin = new frmLogin();
frmLogin.Closing += new
System.ComponentModel.CancelEventHandler(this.frmLogin_Closing);
frmLogin.ShowDialog();
}

private void frmLogin_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
panel5.Visible = true;
button1.Visible = true;
panel6.Visible = true;
dataGrid1.Visible = true;
}


frmLogin.Closing += new ClosingHan
 
R

rhaazy

I have no idea whats going on here. If you could explain a bit more
how this is going to help me with my problem maybe I can get it
working. Making chose changes doesn't get me any closer, if anything
the compiler just throws more errors..
 
P

Pritcham

Hi

I'm assuming that the code you originally listed in your post was from
the 2 forms (i.e. the 'private void frmMDIMain_Load' sub was in your
frmMDIMain's code, and the 'private void frmLogin_Closing' code was in
your frmLogin code?

The above poster basically 'moved' the code from frmLogin into your
frmMDIMain form and added an event listener which responds to the
frmLogin closing event and fires the sub accordingly. This way you're
not having to reference the main form from your login form. Hope that
makes sense.

Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top