473,221 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

Hiding main window at startup

Hello. I've written an app that I want to "live" in the system tray.
I want it to start up with just a tray icon showing, and if the user
selects "Settings..." from the icon's context menu, to display a
window that will allow him to change settings. When he hits "OK" or
"Cancel", the window should hide again.

At first, I tried putting a "Me.Visible = False" in the form's Load
event, but apparently that code runs before the command can be
effective. I moved the line to the Activate event, which hid the form
at startup just fine; however, when I tried to set Me.Visible to True
in another part of the code, I saw the Form.Activate event running
again, re-hiding the form.

On my second try, I created a form-level variable, WindowVisible, put
Me.Visible = WindowVisible in the Form.Activate event, and set
WindowVisible in the code where necessary. This works fine, but it
seems a little kludgy to me, as if I'm trying to work around something
I don't understand.

My questions are:

1. Is there a better way to hide a form at startup?

2. Is there a better way to approach the whole problem?

3. Where can I read a summary of the order in which form events are
raised, and for what reasons?

Thanks a lot.
Nov 20 '05 #1
4 1873
Tony,
2. Is there a better way to approach the whole problem? Yes.

Matthew MacDonald's book "Microsoft Visual Basic .NET Programmer's Cookbook"
has a topic on creating a system tray program.

Basically: Rather than using a Form as the startup object, use a Component
instead.

Create a new Component class (use Project - Add Component). Add a NotifyIcon
to the component designer. Also add a ContextMenu object for the
NotifyIcon. When you click the menu, create and show the form. Remember to
put an Exit option on the menu.

Make the Component the startup object, adding a Shared Sub Main to the
component.

Public Class Component1
Inherits System.ComponentModel.Component

' Component designer generated code omitted.

Public Shared Sub Main
Dim app as New Component1
Application.Run()
End Sub

Private Sub menuOptions_Click(...) Handles menuOptions.Click
' this would be your settings dialog.
Dim dialog as New OptionsDialog
dialog.ShowDialog()
dialog.Dispose()
End Sub

Private Sub menuExit_Click(...) Handles menuExit.Click
Me.Dispose()
Application.Exit()
End Sub

End Sub

The problem is you cannot edit the menu from the Component Designer. What I
do is use cut & paste from a Form Designer onto the Component Designer to
get the menu to the component...

The call to Me.Dispose enables the icon to be removed from the system tray
right away rather then waiting.

Hope this helps
Jay
"Tony Vitonis" <no***@nowhere.com> wrote in message
news:MP************************@news.md.comcast.gi ganews.com... Hello. I've written an app that I want to "live" in the system tray.
I want it to start up with just a tray icon showing, and if the user
selects "Settings..." from the icon's context menu, to display a
window that will allow him to change settings. When he hits "OK" or
"Cancel", the window should hide again.

At first, I tried putting a "Me.Visible = False" in the form's Load
event, but apparently that code runs before the command can be
effective. I moved the line to the Activate event, which hid the form
at startup just fine; however, when I tried to set Me.Visible to True
in another part of the code, I saw the Form.Activate event running
again, re-hiding the form.

On my second try, I created a form-level variable, WindowVisible, put
Me.Visible = WindowVisible in the Form.Activate event, and set
WindowVisible in the code where necessary. This works fine, but it
seems a little kludgy to me, as if I'm trying to work around something
I don't understand.

My questions are:

1. Is there a better way to hide a form at startup?

2. Is there a better way to approach the whole problem?

3. Where can I read a summary of the order in which form events are
raised, and for what reasons?

Thanks a lot.

Nov 20 '05 #2
Here is what I know that works....
1 - first of all use the notifyicon control if you want
it to run in the system try
2 - then on the form itself set its showintaskbar
property to false and/or min and max properties to false
as well (if you want)
3 - to hide the form put the code in
Protected Overloads Sub OnVisibleChanged(ByVal e As
System.EventArgs)

'other code if any....
'then...
if Me.Visible = True Then Me.Visible = False

'Other code if any...
End Sub

4 -
you can use "Protected Overrides Sub OnClick(ByVal e As
System.EventArgs)" to fire up the items in the context
menu.
5 - Use "Protected Overrides Sub OnLoad(ByVal e As
System.EventArgs)" instead of Form_load event.

This should work.

-----Original Message-----
Hello. I've written an app that I want to "live" in the system tray.I want it to start up with just a tray icon showing, and if the userselects "Settings..." from the icon's context menu, to display awindow that will allow him to change settings. When he hits "OK" or"Cancel", the window should hide again.

At first, I tried putting a "Me.Visible = False" in the form's Loadevent, but apparently that code runs before the command can beeffective. I moved the line to the Activate event, which hid the format startup just fine; however, when I tried to set Me.Visible to Truein another part of the code, I saw the Form.Activate event runningagain, re-hiding the form.

On my second try, I created a form-level variable, WindowVisible, putMe.Visible = WindowVisible in the Form.Activate event, and setWindowVisible in the code where necessary. This works fine, but itseems a little kludgy to me, as if I'm trying to work around somethingI don't understand.

My questions are:

1. Is there a better way to hide a form at startup?

2. Is there a better way to approach the whole problem?

3. Where can I read a summary of the order in which form events areraised, and for what reasons?

Thanks a lot.
.

Nov 20 '05 #3
I ran into the same problem the other day. I found that if
you set a form as the startup you cannot hide it on
startup. So i defined in that form a Sub Main and set that
sub main as my startup.

Then I was able to hide it on startup with Me.Hide()

Shawn Regan
-----Original Message-----
Hello. I've written an app that I want to "live" in the system tray.I want it to start up with just a tray icon showing, and if the userselects "Settings..." from the icon's context menu, to display awindow that will allow him to change settings. When he hits "OK" or"Cancel", the window should hide again.

At first, I tried putting a "Me.Visible = False" in the form's Loadevent, but apparently that code runs before the command can beeffective. I moved the line to the Activate event, which hid the format startup just fine; however, when I tried to set Me.Visible to Truein another part of the code, I saw the Form.Activate event runningagain, re-hiding the form.

On my second try, I created a form-level variable, WindowVisible, putMe.Visible = WindowVisible in the Form.Activate event, and setWindowVisible in the code where necessary. This works fine, but itseems a little kludgy to me, as if I'm trying to work around somethingI don't understand.

My questions are:

1. Is there a better way to hide a form at startup?

2. Is there a better way to approach the whole problem?

3. Where can I read a summary of the order in which form events areraised, and for what reasons?

Thanks a lot.
.

Nov 20 '05 #4
* "Shawn Regan" <an*******@discussions.microsoft.com> scripsit:
I ran into the same problem the other day. I found that if
you set a form as the startup you cannot hide it on
startup. So i defined in that form a Sub Main and set that
sub main as my startup.


Just call 'Application.Run' in a 'Sub Main' (set as startup object) and
show the window by instantiating it and calling its 'Show' method.

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: andre | last post by:
HI, I’m learning C# and already know VB .Net. I noticed that C# you have a Static Void Main () (entry point of the app). Well that got me thinking, I was told that VB.net removed “The...
6
by: PMBragg | last post by:
Thank you in advance for any and all assistance. Is there a way to hide the Main Access window with tables, queries, forms etc programmatically? Michael
1
by: Ronald Santos | last post by:
I just converted an Access97 application database to Access XP. My problem is that everytime I start the application, the database window always appear. I already uncheck the Display Database...
0
by: Mark Reed | last post by:
Hi all, Access 2002 XP platform. I am trying to learn a little about programming (I know next to nothing so far) and have found some code which hides the toolbars. However, this bit of code is a...
6
by: Marc | last post by:
I am just starting out teaching myself C#, and I have come accross a confusing point in my book. It seems that any class can have a Main() function, but what does that mean? Is the Main() function...
7
by: Danielb | last post by:
I want my application to run most of the time as just an notify icon visible in the system tray, with some dialogs windows that open if the user selects an option from the context menu on the tray...
8
by: Michael Rich | last post by:
I am writing a program that primaryly runs in the system tray. When the program starts, I would like to hide the main form and only show the tray icon. in the Form Load event I set Me.Visible =...
5
by: BA | last post by:
Hi there I am trying to write an "application" in Access 2000, that displays a front end and allows the user to interact with the database without seeing Access loaded, in the background, nor on...
3
by: Anthony P. | last post by:
Hello Everyone, I'm writing an application that, so far, only has three forms: frmSplashScreen frmLicenseScreen frmConfigurationScreen Now, frmSplashScreen has a timer that sits it on...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.