me.Visible = false in Form_Load doesn't work

  • Thread starter Thread starter Martin G. Brown
  • Start date Start date
M

Martin G. Brown

I am trying to write a system tray application. I want it to have an
invisible window when it loads, with just an icon in the bottom right of the
screen.

I have placed the following line in the Form_Load event but it doesn't seem
to work.

me.Visible = false

The form just gets displayed anyway, no error messages. The VisibleChanged
event fires twice once when I set the value and again immediately after the
Form_Load event, this second time the value of me.Visible is true.

I have tried putting the code in various events but I get a rather annoying
"flash" of the form before it disappears.

for example

Dim bFirst as boolean = true
Private Sub Form_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
if bFirst then
bFirst = false
me.Visible = false
end if
End Sub


Does anyone have any ideas?

Martin
 
I do apologise for my last post. I had missed that fact that the exact same
question had been asked and answered before.

The answer seems to lie in using a minimized form with the show in task bar
property set to false.

Martin
 
* "Martin G. Brown said:
I am trying to write a system tray application. I want it to have an
invisible window when it loads, with just an icon in the bottom right of the
screen.

I have placed the following line in the Form_Load event but it doesn't seem
to work.

me.Visible = false

The form just gets displayed anyway, no error messages. The VisibleChanged
event fires twice once when I set the value and again immediately after the
Form_Load event, this second time the value of me.Visible is true.

I have tried putting the code in various events but I get a rather annoying
"flash" of the form before it disappears.

In addition to the other posts:

The form will be shown directly after the 'Load' event.
 
I am trying to write a system tray application. I want it to have an
invisible window when it loads, with just an icon in the bottom right of the
screen.

Instead of using a form, start the app using a component class. Add a
component to your application and put the icon and optionally a context
menu on that. Then create a shared sub main in that component and use that
as the start up.

HTH
 
I have been trying to get this to work, however the Application.Run method
won't take a component class as an argument. I guess that I am just missing
something, would it be possible for you to give an example that we could
look at?

Martin
 
I have finally cracked it.

All you have to do is to create your form before calling Application.Run.
Then when you want the application to end you call Application.End.

So...

[STAThread]
static void Main()
{
Application.Run(new Magnifier());
}

becomes...

[STAThread]
static void Main()
{
Magnifier m = new Magnifier();
m.Visible = false;
m.Activate();
Application.Run();
}

With the addition of something like this...

private void menuExit_Click(object sender, System.EventArgs e)
{
Application.Exit();
}

the whole thing starts to fall into place.

For a slightly longer explanation see:
http://www.mgbrown.com/2003_11_02_MGBlogArchive.asp#106806083681987263

Martin G. Brown
http://www.mgbrown.com
 
Back
Top