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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ThunderMusic

    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.Componen tModel.CancelEv entArgs) Handles MyBase.Closing
    If Not m_ClosingApp Then
    e.Cancel = True
    Me.Visible = False
    Me.ShowInTaskba r = False
    End If
    End Sub

    Private Sub NIMS_DoubleClic k(ByVal sender As Object, ByVal e As
    System.EventArg s) Handles NIMS.DoubleClic k
    Me.Visible = True
    Me.ShowInTaskba r = True

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

    Private Sub MNUOpen_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles MNUOpen.Click
    Me.Visible = True
    Me.ShowInTaskba r = True

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

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

    private m_ClosingApp as boolean


  • ThunderMusic

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

    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.ShowInTaskB ar = 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):
    [color=blue]
    > FRMMain.TVAll_A fterSelect(Obje ct sender = {System.Windows .Forms.TreeView },[/color]
    ....)
    [<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


    "ThunderMus ic" <NOdanylat@symp atico.caSPAMATA LL> a écrit dans le message de
    news:eSI45q5oFH A.1088@TK2MSFTN GP14.phx.gbl...[color=blue]
    > 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[/color]
    Messenger.[color=blue]
    >
    > But one problem arose. When I close the form (the first time), it[/color]
    disappears[color=blue]
    > (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[/color]
    disappears...[color=blue]
    > 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[/color]
    would[color=blue]
    > be a problem.
    >
    > Thanks
    >
    > ThunderMusic
    >
    > Private Sub FRMMain_Closing (ByVal sender As Object, ByVal e As
    > System.Componen tModel.CancelEv entArgs) Handles MyBase.Closing
    > If Not m_ClosingApp Then
    > e.Cancel = True
    > Me.Visible = False
    > Me.ShowInTaskba r = False
    > End If
    > End Sub
    >
    > Private Sub NIMS_DoubleClic k(ByVal sender As Object, ByVal e As
    > System.EventArg s) Handles NIMS.DoubleClic k
    > Me.Visible = True
    > Me.ShowInTaskba r = True
    >
    > If Me.WindowState = FormWindowState .Minimized Then
    > Me.WindowState = FormWindowState .Normal
    > End If
    > End Sub
    >
    > Private Sub MNUOpen_Click(B yVal sender As System.Object, ByVal e As
    > System.EventArg s) Handles MNUOpen.Click
    > Me.Visible = True
    > Me.ShowInTaskba r = True
    >
    > If Me.WindowState = FormWindowState .Minimized Then
    > Me.WindowState = FormWindowState .Normal
    > End If
    > End Sub
    >
    > Private Sub MNUExit_Click(B yVal sender As Object, ByVal e As
    > System.EventArg s) Handles MNUExit.Click
    > m_ClosingApp = True
    > Me.Close()
    > End Sub
    >
    > private m_ClosingApp as boolean
    >
    >[/color]


    Comment

    • Armin Zingler

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

      "ThunderMus ic" <NOdanylat@symp atico.caSPAMATA LL> schrieb im Newsbeitrag
      news:eSI45q5oFH A.1088@TK2MSFTN GP14.phx.gbl...[color=blue]
      > 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][/color]

      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.visiblecha nged event, you'll see that the
      ShowInTaskbar property procedure indeed shows the Form again. Here's the
      callstack:

      WindowsApplicat ion.Form1.Form1 _VisibleChanged (sender, e) Zeile 119 Basic
      System.Windows. Forms.Control.O nVisibleChanged (e)
      System.Windows. Forms.Scrollabl eControl.OnVisi bleChanged(e)
      System.Windows. Forms.Form.OnVi sibleChanged(e)
      System.Windows. Forms.Control.S etVisibleCore(v alue)
      System.Windows. Forms.Form.SetV isibleCore(valu e)
      System.Windows. Forms.Control.s et_Visible(valu e)
      System.Windows. Forms.Form.Crea teHandle()
      System.Windows. Forms.Control.R ecreateHandleCo re()
      System.Windows. Forms.Form.Recr eateHandleCore( )
      System.Windows. Forms.Control.R ecreateHandle()
      System.Windows. Forms.Form.set_ ShowInTaskbar(v alue)
      WindowsApplicat ion.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

      Comment

      • Armin Zingler

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

        "ThunderMus ic" <NOdanylat@symp atico.caSPAMATA LL> schrieb[color=blue]
        > 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.ShowInTaskB ar = 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):
        >[color=green]
        > > FRMMain.TVAll_A fterSelect(Obje ct sender =
        > > {System.Windows .Forms.TreeView },[/color]
        > ...)
        > [<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?[/color]


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


        Armin

        Comment

        Working...