Making main form initially hidden...?

A

Andrew Kilgore

Hi all,

Today is my first day at programming using .NET so please excuse if my
question seems trivial.
(All previous coding done with C++/MFC)

My aim is to create an application (consisting of a single form) which, when
started, will place an icon in the system tray and allow me to interact with
the application/main form via a context menu. No problems with this...

The problem is that when the applications starts, the main form (which
creates the tray icon etc.) is displayed. I don't want this - instead I only
want the main form to be made visible when the user selects the appropriate
item from the tray icon's context menu.

I've tried setting the form's 'Visible' property to false and also calling
it's 'Hide()' method during the form's creation but without luck. It seems
as if the line:
Application.Run(new SettingsForm());

is creating and displaying the form regardless of any properties I set prior
to it's call or during form creation.

Any help would be much appreciated.
Alternatively, it there is a better way to accomplish my goal please feel
free to educate me in the ways of .NET ;o)

Many thanks,
Andy.
 
C

Chris Dunaway

If you instantiate the form outside of the Application.Run call, you
can show it as you need (beware off the top of my head code follows):

'This variable declared globally somewhere
Dim frmMain As Form1 'use your form name here

Public Sub Main(...)

'Insert code here to insert icon in system tray

'Instantiate the form, but it is not shown yet
'You may even want to defer creating the form object until the
'user clicks your tray icon.

frmMain = New Form1 'use your form name here

'This call to Application.Run will not show the form
'REMEMBER: You must call Application.ExitThread later on to exit
the
'app.

Application.Run()
End Sub
 
A

Andrew Kilgore

Hi Chris,

Thank you for your help...
It certainly is a lot better than my workaround which was to set
'ShowInTaskbar' to false and have the main form appear minimized :blush:)

Many thanks,
Andy.
 

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