Why does this.Hide not work (as expected) ?

M

Martin M

Hello,

please take a look at this very simple program built up with VS2005 with the
form designer:
namespace TestHide
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
this.Hide ();
}
}
}
What happens when I click the button is that the form disappears but not
only from the desktop, also from the taskbar and also from the task manager |
applications tab. All that is left is that it is still in the task manager
processes tab. But there is no chance for me to get it back on the desktop.

I would have expected, that it would remain in the taskbar like when I click
the minimize button.

What did I do wrong or how can I achieve the desired function?

Thank you for any help

Martin
 
A

Alberto Poblacion

Martin M said:
[...]
this.Hide ();
[...]
What happens when I click the button is that the form disappears but not
only from the desktop, also from the taskbar and also from the task
manager |
applications tab. All that is left is that it is still in the task manager
processes tab. But there is no chance for me to get it back on the
desktop.

I would have expected, that it would remain in the taskbar like when I
click
the minimize button.

What did I do wrong or how can I achieve the desired function?

The Hide method does the opposite of the Show method, in the sense that
it makes the form no longer visible. Since the taskbar shows by default the
forms that are visible, it no longer appears there. Normally, you would only
use this method on secondary Forms that have been opened from your main
form. The main form would have some UI element to show the secondary form
when needed.

To achieve the result that you are seeking (form not visible on screen,
but visible on the taskbar), what you need to do is _minimize_ the form.
This can be done in code by means of this.WindowState =
FormWindowState.Minimized.
 
M

Martin M

Hi Alberto,

thnak you for your answer.
This can be done in code by means of this.WindowState =
FormWindowState.Minimized.

I tried this and got this error:
error CS0117: 'System.Windows.Forms.FormWindowState' does not contain a
definition for 'Minimized'
I also tried Maximized and Normal which compiled well.
Then I deleted .Miniminzed and reenter the dot to get the context menu
offering the possibilities and that only displayed Normal and Maximized.
Is this because it is a project for WinCE with Compact Framework 2.0

Any help is welcome

Thank you

Martin
 
A

Alberto Poblacion

Martin M said:
error CS0117: 'System.Windows.Forms.FormWindowState' does not contain a
definition for 'Minimized'
I also tried Maximized and Normal which compiled well.
Then I deleted .Miniminzed and reenter the dot to get the context menu
offering the possibilities and that only displayed Normal and Maximized.
Is this because it is a project for WinCE with Compact Framework 2.0

Ah, I thought that it was a standard Windows Forms project, where you
can minimize forms to the taskbar. I don't think that forms can me minimized
in Windows CE. Maybe someone else can suggest another alternative for this
environment.
 
M

Martin M

Hi Alberto,

and thank you for your answer.
I wasn't aware about that difference either. I can minimize that form in Win
CE but only from the button on the title bar as we are used to in desktop Win.

I hope there will be some solution.

Martin
 
J

Jeff Johnson

Is this because it is a project for WinCE with Compact Framework 2.0

So next time you ask a question please be sure to mention this very
important fact!
 
M

Martin M

Hello Jeff,

Jeff Johnson said:
So next time you ask a question please be sure to mention this very
important fact!

Please excuse me. I tried my first thing , this.Hide, in CE and desktop and
it didn't work on both, so I thought there must be a general reason. And that
is, as Alberto answered. The CE special thing came in later.
But I will try to mention my environment when I ask the question in future.

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