Context Menu problem

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

    #1

    Context Menu problem

    Hi all,

    Lately I have been working on an application in VB .net CF for Pocket PC
    device. I have a small question about Context Menu.

    When I try to close the window after context menu is poped up, the window
    does not closes until I click on the window. Below is the code. Hopefully,
    you can help me out.


    Friend WithEvents ContextMenu1 As System.Windows. Forms.ContextMe nu
    -----Remember ContextMenu1 has no menu items added.---------
    'Setting context menu for the listview. When user holds the mouse on the
    listview item, then context menu pop up event is fired. Look below to see the
    code
    Me.ListView1.Co ntextMenu = Me.ContextMenu1

    Private Sub ContextMenu1_Po pup(ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles ContextMenu1.Po pup
    Me.Close() 'The window does not closes. Don't know why
    End Sub

    Your help will be appreciated


  • W.G. Ryan eMVP

    #2
    Re: Context Menu problem

    Mohit:

    I'm not sure I follow what you're trying to do. Popup is triggered right
    before the menu is shown. As such, why would you want to close the form
    it's based on before it's shown - nothing could be selected if you could
    successfully close it. If you do it successfully I'm pretty cure you're
    going to raise an exception - b/c you can't access a disposed object. You
    don't know for sure exactly the sequence that will fire but close is going
    to call dispose so the sender won't exist.

    --
    W.G. Ryan MVP (Windows Embedded)

    TiBA Solutions
    www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
    "Mohit Gupta" <MohitGupta@dis cussions.micros oft.com> wrote in message
    news:34222998-181F-493C-BEB3-D9EF4C103610@mi crosoft.com...[color=blue]
    > Hi all,
    >
    > Lately I have been working on an application in VB .net CF for Pocket PC
    > device. I have a small question about Context Menu.
    >
    > When I try to close the window after context menu is poped up, the window
    > does not closes until I click on the window. Below is the code. Hopefully,
    > you can help me out.
    >
    >
    > Friend WithEvents ContextMenu1 As System.Windows. Forms.ContextMe nu
    > -----Remember ContextMenu1 has no menu items added.---------
    > 'Setting context menu for the listview. When user holds the mouse on[/color]
    the[color=blue]
    > listview item, then context menu pop up event is fired. Look below to see[/color]
    the[color=blue]
    > code
    > Me.ListView1.Co ntextMenu = Me.ContextMenu1
    >
    > Private Sub ContextMenu1_Po pup(ByVal sender As System.Object, ByVal e[/color]
    As[color=blue]
    > System.EventArg s) Handles ContextMenu1.Po pup
    > Me.Close() 'The window does not closes. Don't know why
    > End Sub
    >
    > Your help will be appreciated
    >
    >[/color]


    Comment

    • Mohit Gupta

      #3
      Re: Context Menu problem

      HI Ryan

      Actually, let me explain what I am doing.

      THere is a LISTVIEW object in an application that has, for example, 10 rows.
      Now, as I am developing on .NET CF framework, which in other words means an
      applicaiton is developed for Pocket PC. Therefore, what I want to do is to
      hold the stylus on to the item until context menu popup event is fired.

      For that reason I created a new ContextMenu object having no menu items in
      it. I assigned this context menu to LISTVIEW object. Without any problems,
      context menu popup is fired when I hold my stylus for longer period of time
      on the selected item.

      For more information, every item has an ID associated (in this example) with
      it. When an item is selected and context menu pop up is fired, I pass that ID
      to the next form that I show as a dialog box. Once the form dialog if closed,
      I come back to my context menu popup function and want to close the parent
      window. But when I try to close it nothing happens until stylus touches the
      screen.

      Bit for more code


      Private Sub ContextMenu1_Po pup(ByVal sender As System.Object, ByVal e As
      System.EventArg s) Handles ContextMenu1.Po pup
      Dim formObj As New Form2
      formObj.setValu es(ListView1.se lectedItem(0).t ext)
      formObj.showDia log() 'Perform some task and close it
      'After the dialog form is closed, close this window as well.
      Me.Close() 'The window does not closes. Don't know why
      End Sub

      I think now you have more idea of what I am trying to do. Definitely there
      is another way, if you are thinking about it, for example, have a button and
      perform the same task when the button is clicked. I have already been
      successful that way but I want to resolve the above mentioned issue.



      "W.G. Ryan eMVP" wrote:
      [color=blue]
      > Mohit:
      >
      > I'm not sure I follow what you're trying to do. Popup is triggered right
      > before the menu is shown. As such, why would you want to close the form
      > it's based on before it's shown - nothing could be selected if you could
      > successfully close it. If you do it successfully I'm pretty cure you're
      > going to raise an exception - b/c you can't access a disposed object. You
      > don't know for sure exactly the sequence that will fire but close is going
      > to call dispose so the sender won't exist.
      >
      > --
      > W.G. Ryan MVP (Windows Embedded)
      >
      > TiBA Solutions
      > www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
      > "Mohit Gupta" <MohitGupta@dis cussions.micros oft.com> wrote in message
      > news:34222998-181F-493C-BEB3-D9EF4C103610@mi crosoft.com...[color=green]
      > > Hi all,
      > >
      > > Lately I have been working on an application in VB .net CF for Pocket PC
      > > device. I have a small question about Context Menu.
      > >
      > > When I try to close the window after context menu is poped up, the window
      > > does not closes until I click on the window. Below is the code. Hopefully,
      > > you can help me out.
      > >
      > >
      > > Friend WithEvents ContextMenu1 As System.Windows. Forms.ContextMe nu
      > > -----Remember ContextMenu1 has no menu items added.---------
      > > 'Setting context menu for the listview. When user holds the mouse on[/color]
      > the[color=green]
      > > listview item, then context menu pop up event is fired. Look below to see[/color]
      > the[color=green]
      > > code
      > > Me.ListView1.Co ntextMenu = Me.ContextMenu1
      > >
      > > Private Sub ContextMenu1_Po pup(ByVal sender As System.Object, ByVal e[/color]
      > As[color=green]
      > > System.EventArg s) Handles ContextMenu1.Po pup
      > > Me.Close() 'The window does not closes. Don't know why
      > > End Sub
      > >
      > > Your help will be appreciated
      > >
      > >[/color]
      >
      >
      >[/color]

      Comment

      • W.G. Ryan eMVP

        #4
        Re: Context Menu problem

        Ok, so there's something going on in between popup and close...

        Anyway, I have form1, Form2 and form3. On form2 I have a listView with an
        empty context menu. When form1 loads I declare a new Form2 and show it. On
        Popup on Form2 I have the following code:
        Dim f3 As New Form3

        Select Case f3.ShowDialog

        Case DialogResult.OK

        Me.Close()

        End Select

        On Form3 I stuck this behind a button just to get it to close ---

        Me.DialogResult = DialogResult.OK



        I've run it on my iMATE and a iPAQ 1940 as well as the emulator, it works as
        expected each time. You may want to try Application.DoE vents because it's
        possible that your screen just isn't refreshing although I doubt it. I
        can't seem to replicate the behavior


        --
        W.G. Ryan MVP (Windows Embedded)

        TiBA Solutions
        www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
        "Mohit Gupta" <MohitGupta@dis cussions.micros oft.com> wrote in message
        news:F34E0831-54A5-48C0-8634-DAC9F4AED383@mi crosoft.com...[color=blue]
        > HI Ryan
        >
        > Actually, let me explain what I am doing.
        >
        > THere is a LISTVIEW object in an application that has, for example, 10[/color]
        rows.[color=blue]
        > Now, as I am developing on .NET CF framework, which in other words means[/color]
        an[color=blue]
        > applicaiton is developed for Pocket PC. Therefore, what I want to do is to
        > hold the stylus on to the item until context menu popup event is fired.
        >
        > For that reason I created a new ContextMenu object having no menu items in
        > it. I assigned this context menu to LISTVIEW object. Without any problems,
        > context menu popup is fired when I hold my stylus for longer period of[/color]
        time[color=blue]
        > on the selected item.
        >
        > For more information, every item has an ID associated (in this example)[/color]
        with[color=blue]
        > it. When an item is selected and context menu pop up is fired, I pass that[/color]
        ID[color=blue]
        > to the next form that I show as a dialog box. Once the form dialog if[/color]
        closed,[color=blue]
        > I come back to my context menu popup function and want to close the parent
        > window. But when I try to close it nothing happens until stylus touches[/color]
        the[color=blue]
        > screen.
        >
        > Bit for more code
        >
        >
        > Private Sub ContextMenu1_Po pup(ByVal sender As System.Object, ByVal e As
        > System.EventArg s) Handles ContextMenu1.Po pup
        > Dim formObj As New Form2
        > formObj.setValu es(ListView1.se lectedItem(0).t ext)
        > formObj.showDia log() 'Perform some task and close it
        > 'After the dialog form is closed, close this window as well.
        > Me.Close() 'The window does not closes. Don't know why
        > End Sub
        >
        > I think now you have more idea of what I am trying to do. Definitely there
        > is another way, if you are thinking about it, for example, have a button[/color]
        and[color=blue]
        > perform the same task when the button is clicked. I have already been
        > successful that way but I want to resolve the above mentioned issue.
        >
        >
        >
        > "W.G. Ryan eMVP" wrote:
        >[color=green]
        > > Mohit:
        > >
        > > I'm not sure I follow what you're trying to do. Popup is triggered[/color][/color]
        right[color=blue][color=green]
        > > before the menu is shown. As such, why would you want to close the form
        > > it's based on before it's shown - nothing could be selected if you could
        > > successfully close it. If you do it successfully I'm pretty cure you're
        > > going to raise an exception - b/c you can't access a disposed object.[/color][/color]
        You[color=blue][color=green]
        > > don't know for sure exactly the sequence that will fire but close is[/color][/color]
        going[color=blue][color=green]
        > > to call dispose so the sender won't exist.
        > >
        > > --
        > > W.G. Ryan MVP (Windows Embedded)
        > >
        > > TiBA Solutions
        > > www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
        > > "Mohit Gupta" <MohitGupta@dis cussions.micros oft.com> wrote in message
        > > news:34222998-181F-493C-BEB3-D9EF4C103610@mi crosoft.com...[color=darkred]
        > > > Hi all,
        > > >
        > > > Lately I have been working on an application in VB .net CF for[/color][/color][/color]
        Pocket PC[color=blue][color=green][color=darkred]
        > > > device. I have a small question about Context Menu.
        > > >
        > > > When I try to close the window after context menu is poped up, the[/color][/color][/color]
        window[color=blue][color=green][color=darkred]
        > > > does not closes until I click on the window. Below is the code.[/color][/color][/color]
        Hopefully,[color=blue][color=green][color=darkred]
        > > > you can help me out.
        > > >
        > > >
        > > > Friend WithEvents ContextMenu1 As System.Windows. Forms.ContextMe nu
        > > > -----Remember ContextMenu1 has no menu items added.---------
        > > > 'Setting context menu for the listview. When user holds the mouse[/color][/color][/color]
        on[color=blue][color=green]
        > > the[color=darkred]
        > > > listview item, then context menu pop up event is fired. Look below to[/color][/color][/color]
        see[color=blue][color=green]
        > > the[color=darkred]
        > > > code
        > > > Me.ListView1.Co ntextMenu = Me.ContextMenu1
        > > >
        > > > Private Sub ContextMenu1_Po pup(ByVal sender As System.Object,[/color][/color][/color]
        ByVal e[color=blue][color=green]
        > > As[color=darkred]
        > > > System.EventArg s) Handles ContextMenu1.Po pup
        > > > Me.Close() 'The window does not closes. Don't know why
        > > > End Sub
        > > >
        > > > Your help will be appreciated
        > > >
        > > >[/color]
        > >
        > >
        > >[/color][/color]


        Comment

        • Mohit Gupta

          #5
          Re: Context Menu problem

          Hi Ryan,

          I have done the same, but problem still seems to exists. As soon as my
          stylus hits the screen, my screen closes. I think my event is still pending.
          It resumes when stylus hits the ground. Is there any way to explicity call
          the hit of stylus on the screen?



          "W.G. Ryan eMVP" wrote:
          [color=blue]
          > Ok, so there's something going on in between popup and close...
          >
          > Anyway, I have form1, Form2 and form3. On form2 I have a listView with an
          > empty context menu. When form1 loads I declare a new Form2 and show it. On
          > Popup on Form2 I have the following code:
          > Dim f3 As New Form3
          >
          > Select Case f3.ShowDialog
          >
          > Case DialogResult.OK
          >
          > Me.Close()
          >
          > End Select
          >
          > On Form3 I stuck this behind a button just to get it to close ---
          >
          > Me.DialogResult = DialogResult.OK
          >
          >
          >
          > I've run it on my iMATE and a iPAQ 1940 as well as the emulator, it works as
          > expected each time. You may want to try Application.DoE vents because it's
          > possible that your screen just isn't refreshing although I doubt it. I
          > can't seem to replicate the behavior
          >
          >
          > --
          > W.G. Ryan MVP (Windows Embedded)
          >
          > TiBA Solutions
          > www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
          > "Mohit Gupta" <MohitGupta@dis cussions.micros oft.com> wrote in message
          > news:F34E0831-54A5-48C0-8634-DAC9F4AED383@mi crosoft.com...[color=green]
          > > HI Ryan
          > >
          > > Actually, let me explain what I am doing.
          > >
          > > THere is a LISTVIEW object in an application that has, for example, 10[/color]
          > rows.[color=green]
          > > Now, as I am developing on .NET CF framework, which in other words means[/color]
          > an[color=green]
          > > applicaiton is developed for Pocket PC. Therefore, what I want to do is to
          > > hold the stylus on to the item until context menu popup event is fired.
          > >
          > > For that reason I created a new ContextMenu object having no menu items in
          > > it. I assigned this context menu to LISTVIEW object. Without any problems,
          > > context menu popup is fired when I hold my stylus for longer period of[/color]
          > time[color=green]
          > > on the selected item.
          > >
          > > For more information, every item has an ID associated (in this example)[/color]
          > with[color=green]
          > > it. When an item is selected and context menu pop up is fired, I pass that[/color]
          > ID[color=green]
          > > to the next form that I show as a dialog box. Once the form dialog if[/color]
          > closed,[color=green]
          > > I come back to my context menu popup function and want to close the parent
          > > window. But when I try to close it nothing happens until stylus touches[/color]
          > the[color=green]
          > > screen.
          > >
          > > Bit for more code
          > >
          > >
          > > Private Sub ContextMenu1_Po pup(ByVal sender As System.Object, ByVal e As
          > > System.EventArg s) Handles ContextMenu1.Po pup
          > > Dim formObj As New Form2
          > > formObj.setValu es(ListView1.se lectedItem(0).t ext)
          > > formObj.showDia log() 'Perform some task and close it
          > > 'After the dialog form is closed, close this window as well.
          > > Me.Close() 'The window does not closes. Don't know why
          > > End Sub
          > >
          > > I think now you have more idea of what I am trying to do. Definitely there
          > > is another way, if you are thinking about it, for example, have a button[/color]
          > and[color=green]
          > > perform the same task when the button is clicked. I have already been
          > > successful that way but I want to resolve the above mentioned issue.
          > >
          > >
          > >
          > > "W.G. Ryan eMVP" wrote:
          > >[color=darkred]
          > > > Mohit:
          > > >
          > > > I'm not sure I follow what you're trying to do. Popup is triggered[/color][/color]
          > right[color=green][color=darkred]
          > > > before the menu is shown. As such, why would you want to close the form
          > > > it's based on before it's shown - nothing could be selected if you could
          > > > successfully close it. If you do it successfully I'm pretty cure you're
          > > > going to raise an exception - b/c you can't access a disposed object.[/color][/color]
          > You[color=green][color=darkred]
          > > > don't know for sure exactly the sequence that will fire but close is[/color][/color]
          > going[color=green][color=darkred]
          > > > to call dispose so the sender won't exist.
          > > >
          > > > --
          > > > W.G. Ryan MVP (Windows Embedded)
          > > >
          > > > TiBA Solutions
          > > > www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
          > > > "Mohit Gupta" <MohitGupta@dis cussions.micros oft.com> wrote in message
          > > > news:34222998-181F-493C-BEB3-D9EF4C103610@mi crosoft.com...
          > > > > Hi all,
          > > > >
          > > > > Lately I have been working on an application in VB .net CF for[/color][/color]
          > Pocket PC[color=green][color=darkred]
          > > > > device. I have a small question about Context Menu.
          > > > >
          > > > > When I try to close the window after context menu is poped up, the[/color][/color]
          > window[color=green][color=darkred]
          > > > > does not closes until I click on the window. Below is the code.[/color][/color]
          > Hopefully,[color=green][color=darkred]
          > > > > you can help me out.
          > > > >
          > > > >
          > > > > Friend WithEvents ContextMenu1 As System.Windows. Forms.ContextMe nu
          > > > > -----Remember ContextMenu1 has no menu items added.---------
          > > > > 'Setting context menu for the listview. When user holds the mouse[/color][/color]
          > on[color=green][color=darkred]
          > > > the
          > > > > listview item, then context menu pop up event is fired. Look below to[/color][/color]
          > see[color=green][color=darkred]
          > > > the
          > > > > code
          > > > > Me.ListView1.Co ntextMenu = Me.ContextMenu1
          > > > >
          > > > > Private Sub ContextMenu1_Po pup(ByVal sender As System.Object,[/color][/color]
          > ByVal e[color=green][color=darkred]
          > > > As
          > > > > System.EventArg s) Handles ContextMenu1.Po pup
          > > > > Me.Close() 'The window does not closes. Don't know why
          > > > > End Sub
          > > > >
          > > > > Your help will be appreciated
          > > > >
          > > > >
          > > >
          > > >
          > > >[/color][/color]
          >
          >
          >[/color]

          Comment

          Working...