Mainform show and hide problems

A

Alistair George

Hi in Delphi its a piece of cake to show and hide a mainform eg
mainform.show mainform.hide.
However, after finding similar actions in C# seem to result in destroy
of form object, which causes errors maybe I am wrong, but here is what I
have tried with no joy:
private void TrayFormShow_Click(object sender, EventArgs e)
{
frmMain.ActiveForm.ShowInTaskbar = true;
frmMain.ActiveForm.WindowState = FormWindowState.Maximized;
// or: frmMain.ActiveForm.Visible = true;
}

private void frmMain_Deactivate(object sender, EventArgs e)
{
frmMain.ActiveForm.ShowInTaskbar = false;
frmMain.ActiveForm.WindowState = FormWindowState.Minimized;
// or: frmMain.ActiveForm.Visible = false;
}

Once the frmMain is hidden, then it causes an error when try to show. Do
I have to create a reference object or whats the story thanks.
Al.
 
G

Guest

private void frmMain_Deactivate(object sender, EventArgs e)
this event is fired automatically .at that time form object has been
destroyed .so u should not use this event .beacuse u can not acceess the form
object. better to use differet event . if u are still facing prob .tell me
detail.
 
A

Alistair George

Som said:
this event is fired automatically .at that time form object has been
destroyed .so u should not use this event .beacuse u can not acceess the form
object. better to use differet event . if u are still facing prob .tell me
detail.
Yes, thank you that is what I suspected, but there is no information on
doing this job properly in all the threads I have looked at. For the
sake of completeness, would someone kindly put up the 'approved' method
for showing and hiding forms in the above circumstances.
Even if the resize event is used, when its time to restore there is the
form object needed.
Thank you. Alistair.
 
M

Marko Draca

SomAlistair said:
Yes, thank you that is what I suspected, but there is no information on
doing this job properly in all the threads I have looked at. For the
sake of completeness, would someone kindly put up the 'approved' method
for showing and hiding forms in the above circumstances.
Even if the resize event is used, when its time to restore there is the
form object needed.
Thank you. Alistair.
Are you looking for something like this:

private void frmMain_Resize(object sender, EventArgs e)
{
if (FormWindowState.Minimized == WindowState)
{
this.Hide();
}
}

private void niTray_DoubleClick(object sender, EventArgs e)
{
this.Show();
WindowState = FormWindowState.Normal;
}
 
A

Alistair George

Are you looking for something like this:

private void frmMain_Resize(object sender, EventArgs e)
{
if (FormWindowState.Minimized == WindowState)
{
this.Hide();
}
}

private void niTray_DoubleClick(object sender, EventArgs e)
{
this.Show();
WindowState = FormWindowState.Normal;
}
Crikey, I never used ".this" because I figured it had been lost in
windows deactivate, but it works and perfectly thank you.
 

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