473,385 Members | 1,780 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,385 software developers and data experts.

Very weird problem using NotifyIcon and Context Menu for MSN like form/app closing behavior

Hi,

I'm trying to have a MSN Messenger like form/app closing behavior. When I
click on the X button, I only want the form to disappear and when I
double-click on the notify icon or right-click on it and choose Open from
the context menu, I want the form to reappear. For that, I got the point
covered. Even when the form is minimize, the behavior is like MSN Messenger.

But one problem arose. When I close the form (the first time), it disappears
(that is ok), but after that, when I open it again, it appears, then if I
try to close it (for the second time), it disappears then reappears
immediately, if I close it again (for a third time), then, it disappears...
In fact, except for the first time I close it, I have to close it twice...

I supplied the the code I use (maybe there's a more efficient way to code
it) at the end of this post. I hope that's all the code you need. I only
handle the Closing and Load events for the form, so I don't this this would
be a problem.

Thanks

ThunderMusic

Private Sub FRMMain_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If Not m_ClosingApp Then
e.Cancel = True
Me.Visible = False
Me.ShowInTaskbar = False
End If
End Sub

Private Sub NIMS_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles NIMS.DoubleClick
Me.Visible = True
Me.ShowInTaskbar = True

If Me.WindowState = FormWindowState.Minimized Then
Me.WindowState = FormWindowState.Normal
End If
End Sub

Private Sub MNUOpen_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MNUOpen.Click
Me.Visible = True
Me.ShowInTaskbar = True

If Me.WindowState = FormWindowState.Minimized Then
Me.WindowState = FormWindowState.Normal
End If
End Sub

Private Sub MNUExit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MNUExit.Click
m_ClosingApp = True
Me.Close()
End Sub

private m_ClosingApp as boolean
Nov 21 '05 #1
3 1052
I don't get it at all... I solved the problem and I know which instruction
produced the problem... but I don't know why it causes the problem, maybe
someone could explain it to me?

The instruction causing the problem is "me.ShowInTaskBar = True (or False,
does the same problem)" In fact, I just removed those instructions from my
code and now it works fine (the app doesn't even show in task bar when it is
not visible, so everything is alright). But I don't know why the
ShowInTaskBar property, when toggled, was doing something causing my
TreeView to raise an AfterSelect Event, which seems to get in the way of the
window closing process (in any way). I just don't get why this event is
raised, because when going step-by-step, the call stack shows this (I've cut
some details out for each line, but you have all the lines in the call
stack):
FRMMain.TVAll_AfterSelect(Object sender = {System.Windows.Forms.TreeView}, ....)
[<Non-user Code>]
FRMMain.FRMMain_Closing(Object sender = {JMSFE.FRMMain}, ...)

So if I understand well, the toggling of this property runs some non-user
code, and this non-user code fires the AfterSelect on my TreeView. Does
somebody understand all this? Can somebody explain what is happening?

Thanks

ThunderMusic
"ThunderMusic" <NO*******@sympatico.caSPAMATALL> a écrit dans le message de
news:eS**************@TK2MSFTNGP14.phx.gbl... Hi,

I'm trying to have a MSN Messenger like form/app closing behavior. When I
click on the X button, I only want the form to disappear and when I
double-click on the notify icon or right-click on it and choose Open from
the context menu, I want the form to reappear. For that, I got the point
covered. Even when the form is minimize, the behavior is like MSN Messenger.
But one problem arose. When I close the form (the first time), it disappears (that is ok), but after that, when I open it again, it appears, then if I
try to close it (for the second time), it disappears then reappears
immediately, if I close it again (for a third time), then, it disappears... In fact, except for the first time I close it, I have to close it twice...

I supplied the the code I use (maybe there's a more efficient way to code
it) at the end of this post. I hope that's all the code you need. I only
handle the Closing and Load events for the form, so I don't this this would be a problem.

Thanks

ThunderMusic

Private Sub FRMMain_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If Not m_ClosingApp Then
e.Cancel = True
Me.Visible = False
Me.ShowInTaskbar = False
End If
End Sub

Private Sub NIMS_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles NIMS.DoubleClick
Me.Visible = True
Me.ShowInTaskbar = True

If Me.WindowState = FormWindowState.Minimized Then
Me.WindowState = FormWindowState.Normal
End If
End Sub

Private Sub MNUOpen_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MNUOpen.Click
Me.Visible = True
Me.ShowInTaskbar = True

If Me.WindowState = FormWindowState.Minimized Then
Me.WindowState = FormWindowState.Normal
End If
End Sub

Private Sub MNUExit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MNUExit.Click
m_ClosingApp = True
Me.Close()
End Sub

private m_ClosingApp as boolean

Nov 21 '05 #2
"ThunderMusic" <NO*******@sympatico.caSPAMATALL> schrieb im Newsbeitrag
news:eS**************@TK2MSFTNGP14.phx.gbl...
Hi,

I'm trying to have a MSN Messenger like form/app closing behavior. When I
click on the X button, I only want the form to disappear and when I
double-click on the notify icon or right-click on it and choose Open from
the context menu, I want the form to reappear. For that, I got the point
covered. Even when the form is minimize, the behavior is like MSN
Messenger.

But one problem arose. When I close the form (the first time), it
disappears
(that is ok), but after that, when I open it again, it appears, then if I
try to close it (for the second time), it disappears then reappears
immediately, if I close it again (for a third time), then, it
disappears...
In fact, except for the first time I close it, I have to close it twice...

I supplied the the code I use (maybe there's a more efficient way to code
it) at the end of this post. I hope that's all the code you need. I only
handle the Closing and Load events for the form, so I don't this this
would
be a problem.
[code]


First, I can reproduce the problem. I see your 2nd posting also but let me
first answer this one:
If you set a breakpoint @ the form.visiblechanged event, you'll see that the
ShowInTaskbar property procedure indeed shows the Form again. Here's the
callstack:

WindowsApplication.Form1.Form1_VisibleChanged(send er, e) Zeile 119 Basic
System.Windows.Forms.Control.OnVisibleChanged(e)
System.Windows.Forms.ScrollableControl.OnVisibleCh anged(e)
System.Windows.Forms.Form.OnVisibleChanged(e)
System.Windows.Forms.Control.SetVisibleCore(value)
System.Windows.Forms.Form.SetVisibleCore(value)
System.Windows.Forms.Control.set_Visible(value)
System.Windows.Forms.Form.CreateHandle()
System.Windows.Forms.Control.RecreateHandleCore()
System.Windows.Forms.Form.RecreateHandleCore()
System.Windows.Forms.Control.RecreateHandle()
System.Windows.Forms.Form.set_ShowInTaskbar(value)
WindowsApplication.Form1.Form1_Closing(sender, e) Zeile 100 Basic
If you needed to set this property - you don't as you've already written - I
would have recommended to set it before the visible property. This does
work.
Armin

Nov 21 '05 #3
"ThunderMusic" <NO*******@sympatico.caSPAMATALL> schrieb
I don't get it at all... I solved the problem and I know which
instruction produced the problem... but I don't know why it causes
the problem, maybe someone could explain it to me?

The instruction causing the problem is "me.ShowInTaskBar = True (or
False, does the same problem)" In fact, I just removed those
instructions from my code and now it works fine (the app doesn't
even show in task bar when it is not visible, so everything is
alright). But I don't know why the
ShowInTaskBar property, when toggled, was doing something causing my
TreeView to raise an AfterSelect Event, which seems to get in the
way of the window closing process (in any way). I just don't get why
this event is raised, because when going step-by-step, the call
stack shows this (I've cut some details out for each line, but you
have all the lines in the call stack):
FRMMain.TVAll_AfterSelect(Object sender =
{System.Windows.Forms.TreeView},

...)
[<Non-user Code>]
FRMMain.FRMMain_Closing(Object sender = {JMSFE.FRMMain}, ...)

So if I understand well, the toggling of this property runs some
non-user code, and this non-user code fires the AfterSelect on my
TreeView. Does somebody understand all this? Can somebody explain
what is happening?

In the call stack window's context menu, enable "show non-user code" and
post the call stack again.
Armin

Nov 21 '05 #4

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

Similar topics

3
by: ThunderMusic | last post by:
Hi, I'm trying to have a MSN Messenger like form/app closing behavior. When I click on the X button, I only want the form to disappear and when I double-click on the notify icon or right-click...
2
by: Rob Mayo | last post by:
OK, maybe this is my opinion, maybe these are bugs. Given the folowing: I have a NotifyIcon on my Form, a Context menu associated with the NotifyIcon, and a MenuItem on the ContextMenu set as...
1
by: Zanthor | last post by:
Ok, I've got a small App I'm trying to make minimize to the system tray... The behavior I'm after is that while the forms FormWindowState is Normal I want the form visible in the taskbar, when...
3
by: Me | last post by:
I'm getting a NullReferenceException in Unknown Module when I follow the below steps to create a simple NotifyIcon app that creates the context menu on the fly(see a little analysis after the...
2
by: Eric | last post by:
I implemented owner drawing on the main and context menus of my main form. It works fine. There is also a notify icon control that has a context menu. When the icon is in the status bar, it...
1
by: David | last post by:
Hi, I am developing a NotifyIcon app with C#. I want to show the context menu when user left-clicks on the icon, the same as he/she right-clicks on it. In that event handler,...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
8
by: bole2cant | last post by:
When I add a Button to my NotifyIcon program I get the following: An unhandled exception of type 'System.NullReferenceException' occurred in unknown module. Additional information: Object...
2
by: Phuff | last post by:
I have an application that should run in the system tray while open. It is supposed to be open at all times and I need it to dissapear when the "X" button is pushed on the form...but without...
3
by: SteveMac | last post by:
I am using VS2003 VC++ .NET. I want to make a tray icon with a popup menu (like a context menu) that pops up for a left click. I can make the notifyicon with a context menu and that works fine,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.