|
-
Apr 22nd, 2007, 12:35 PM
#1
Thread Starter
Lively Member
[RESOLVED] [2005] Me.visible = false not working on form load
Hi there,
I am very new to VB.net but not programming per se. However, something has me stumped and I have been as yet unable to find a solution.
I created a very simple form that when loaded should not be visible but have a little systray icon only. The systray icon part works, however the form is not being hidden. This is the code (all of it) that *should* work:
Code:
Public Class Form1
Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
MsgBox("You clicked on the notification icon")
Me.Visible = True
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Visible = False
NotifyIcon1.Visible = True
End Sub
End Class
So why is this not working? Am I missing something here? I took the Me.Visble = False trick from a piece of code I found on the web (link)
If someone could point me in the right direction that would be great!
Thanks in advance.
Mighor
-
Apr 22nd, 2007, 01:18 PM
#2
Re: [2005] Me.visible = false not working on form load
Use the Form Shown event of the form instead
Code:
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
Me.Visible = False
NotifyIcon1.Visible = True
End Sub
-
Apr 22nd, 2007, 02:49 PM
#3
Thread Starter
Lively Member
Re: [2005] Me.visible = false not working on form load
I tried the above code but what happens now is that the form shows for a millisecond and then disappears quickly. What I basically want is the form to not show at all when it is first started up.
I need to make it invisible before it is show, if you know what I mean
-
Apr 22nd, 2007, 02:59 PM
#4
Re: [2005] Me.visible = false not working on form load
Put 'Me.WindowState = FormWindowState.Minimized' in the form_load event. If you also don't want it in the taskbar, use Me.ShowInTaskbar = False.
-
Apr 22nd, 2007, 03:06 PM
#5
Thread Starter
Lively Member
Re: [2005] Me.visible = false not working on form load
Thanks, that did the trick!
I now have the following code and it seems to do exactly what I need it to do:
Code:
Public Class Form1
Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
MsgBox("You clicked on the notification icon")
Me.Visible = True
Me.ShowInTaskbar = True
Me.WindowState = FormWindowState.Normal
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Visible = False
Me.ShowInTaskbar = False
Me.WindowState = FormWindowState.Minimized
End Sub
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
Me.Visible = False
NotifyIcon1.Visible = True
End Sub
End Class
-
Apr 22nd, 2007, 03:11 PM
#6
Re: [2005] Me.visible = false not working on form load
Don't forget to make your project as a Single Instance application, other wise you will see minimized main form instances. Also you don't need to set the Visible property if you use ShowInTaskbar property.
Last edited by VBDT; Apr 22nd, 2007 at 03:14 PM.
-
Apr 22nd, 2007, 03:14 PM
#7
Thread Starter
Lively Member
Re: [2005] Me.visible = false not working on form load
 Originally Posted by VBDT
Don't forget to make your project as a Single Instance application, other wise you will see minimized main form instances.
My application will only have one single window (form). Is this what you meant by Single Instance application?
-
Apr 22nd, 2007, 03:18 PM
#8
Re: [2005] Me.visible = false not working on form load
I mean single instance application. For example when you start your app by clicking the app shortcut icon on your desktop and after it opens you click the shortcut the secont time it will start your app but a diferent instance so you will see two of your forms.
-
Apr 22nd, 2007, 03:21 PM
#9
Thread Starter
Lively Member
Re: [2005] Me.visible = false not working on form load
 Originally Posted by VBDT
I mean single instance application. For example when you start your app by clicking the app shortcut icon on your desktop and after it opens you click the shortcut the secont time it will start your app but a diferent instance so you will see two of your forms.
I see what you mean now. I am not sure how to achieve this. How is this done under Windows and more specifically in Visual Basic? There should indeed be no more than one instance of this application.
-
Apr 22nd, 2007, 03:25 PM
#10
Re: [2005] Me.visible = false not working on form load
Go to your project properties and check the checkbox for "Make Single Instance Application".
-
Apr 22nd, 2007, 03:29 PM
#11
Thread Starter
Lively Member
Re: [2005] Me.visible = false not working on form load
 Originally Posted by VBDT
Go to your project properties and check the checkbox for "Make Single Instance Application".
Haha, ok that was a lot easier than I thought it would be I was already googling for some example code to achieve this and I came across a lot of talk about mutexes and other IPC stuff. I am glad a tickbox is all that is required.
-
Apr 22nd, 2007, 03:34 PM
#12
Re: [2005] Me.visible = false not working on form load
One thing in case you decide to expand your project later on - there is some unexpected behaviour when a form is not shown in the taskbar. For example such a form won't fire the FormClosing event last time I checked.
If you notice strange things happening, first test your thing with ShowInTaskbar set to true.
-
Apr 22nd, 2007, 03:38 PM
#13
Re: [2005] Me.visible = false not working on form load
 Originally Posted by Half
One thing in case you decide to expand your project later on - there is some unexpected behaviour when a form is not shown in the taskbar. For example such a form won't fire the FormClosing event last time I checked.
If you notice strange things happening, first test your thing with ShowInTaskbar set to true.
Yes that is true. It all depends how you exit the application. If you use Application.Exit than it will not fire the FormClosing event, instead use Me.Close.
-
Apr 22nd, 2007, 03:45 PM
#14
Thread Starter
Lively Member
Re: [2005] Me.visible = false not working on form load
 Originally Posted by VBDT
Yes that is true. It all depends how you exit the application. If you use Application.Exit than it will not fire the FormClosing event, instead use Me.Close.
Thanks, I will keep that in mind as I expand on this project.
-
Apr 22nd, 2007, 09:08 PM
#15
Re: [2005] Me.visible = false not working on form load
 Originally Posted by VBDT
Also you don't need to set the Visible property if you use ShowInTaskbar property.
Not true. If you have a minimised form that is not in shown in the task bar it will still appear in the Alt+Tab list. Selecting the form using Alt+Tab will restore it. Not what you want.
What you should do is get rid of the entire Form.Load event handler. You should be setting the WindowState and ShowInTaskbar properties of the form and the Visible property of the NotifyIcon in the designer. All that's left to do then is set the Visible property of the form to False in the Shown event handler.
-
Apr 22nd, 2007, 09:10 PM
#16
Re: [2005] Me.visible = false not working on form load
 Originally Posted by VBDT
Yes that is true. It all depends how you exit the application. If you use Application.Exit than it will not fire the FormClosing event, instead use Me.Close.
Also, not true I'm afraid. Application.Exit does not raise the Closing and Closed events but it does raise the FormClosing and FormClosed events. FormClosing provides the e.CloseReason property so you know how the closure was instigated in the first place. ApplicationExitCall is one of those reasons.
-
Apr 22nd, 2007, 09:14 PM
#17
Re: [2005] Me.visible = false not working on form load
 Originally Posted by jmcilhinney
Not true. If you have a minimised form that is not in shown in the task bar it will still appear in the Alt+Tab list. Selecting the form using Alt+Tab will restore it. Not what you want.
What you should do is get rid of the entire Form.Load event handler. You should be setting the WindowState and ShowInTaskbar properties of the form and the Visible property of the NotifyIcon in the designer. All that's left to do then is set the Visible property of the form to False in the Shown event handler.
I just tested it and you are right! I didn't notice that.
Last edited by VBDT; Apr 22nd, 2007 at 11:31 PM.
-
Apr 22nd, 2007, 09:19 PM
#18
Re: [2005] Me.visible = false not working on form load
 Originally Posted by jmcilhinney
Also, not true I'm afraid. Application.Exit does not raise the Closing and Closed events but it does raise the FormClosing and FormClosed events. FormClosing provides the e.CloseReason property so you know how the closure was instigated in the first place. ApplicationExitCall is one of those reasons.
It is true if the app's main window has its ShowInTaskbar property set to true but if the property is set to false and we call Application.Exit method then for some reason the FormClosing and FomClosed events doesn't fire.
-
Apr 22nd, 2007, 09:36 PM
#19
Re: [2005] Me.visible = false not working on form load
 Originally Posted by VBDT
It is true if the app's main window has its ShowInTaskbar property set to true but if the property is set to false and we call Application.Exit method then for some reason the FormClosing and FomClosed events doesn't fire. 
That I didn't know. One all.
-
Apr 23rd, 2007, 12:27 AM
#20
Thread Starter
Lively Member
Re: [2005] Me.visible = false not working on form load
I am not sure how to do this but as far as I am concerned this thread can be marked as [RESOLVED]. Thanks for all the insights, tips and tricks, people!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|