Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2005

Tip: Looking for answers? Try searching our database.

Making main form initially hidden...?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew Kilgore - 02 Aug 2005 15:11 GMT
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.
Chris Dunaway - 02 Aug 2005 17:53 GMT
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
Andrew Kilgore - 03 Aug 2005 09:53 GMT
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 :o)

Many thanks,
Andy.

> 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):
[quoted text clipped - 19 lines]
>    Application.Run()
> End Sub

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.