hiding a Form on pressure of minimize button

K

kurotsuke

How can I hide a Form (instead of having it reduced to the taskbar)
when the minimize button is pressed in C# (there's an icon in the tray
bar)?
I added the code

protected override void OnResize(EventArgs e)
{
//hide the form
if
(this.WindowState==FormWindowState.Minimized)
{
this.Hide();

this.WindowState=FormWindowState.Normal;
}
else
{
base.OnResize (e);
}
}

The problem is that when I clic on the tray icon the form unhides and
appears minimized (I would like it to be just restored).
Thanks a lot.
Andy
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Yes you can, make a search in the newsgroup, I remember this was asked a
couple of weeks (months?) ago, I posted some code for it, I don;t have the
code here with me thought :(
You have to P/Invoke at least a function, to make the application dissapear
from the taskbar or from using ( alt+tab) .
If you don't find it; or if nobody post it; I will send you the code
tomorrow.

Cheers,
 
R

Ryan LaNeve

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

Yes you can, make a search in the newsgroup, I remember this was asked a
couple of weeks (months?) ago, I posted some code for it, I don;t have the
code here with me thought :(
You have to P/Invoke at least a function, to make the application dissapear
from the taskbar or from using ( alt+tab) .
If you don't find it; or if nobody post it; I will send you the code
tomorrow.

Cheers,

Is there something wrong with the "ShowInTaskbar" property of a form? Set it
to false and the form no longer shows up in the taskbar.

Ryan LaNeve
 
T

Tom Porterfield

kurotsuke said:
How can I hide a Form (instead of having it reduced to the taskbar)
when the minimize button is pressed in C# (there's an icon in the tray
bar)?
I added the code

protected override void OnResize(EventArgs e)
{
//hide the form
if
(this.WindowState==FormWindowState.Minimized)
{
this.Hide();

this.WindowState=FormWindowState.Normal;
}
else
{
base.OnResize (e);
}
}

The problem is that when I clic on the tray icon the form unhides and
appears minimized (I would like it to be just restored).
Thanks a lot.
Andy

In your event that shows the form also set the WindowState to Normal. Note
that you need to set the window state after calling show.
--
Tom Porterfield
MS-MVP MCE
http://support.telop.org

Please post all follow-ups to the newsgroup only.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

IIRC it will still be shown when using ALT+TAB

Cheers,
 

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