Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to disable keydown event in Context Menu Strip ?

How to disable keydown event in Context Menu Strip ?

Scheduled Pinned Locked Moved C#
helptutorialquestion
13 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Varad_Rajan
    wrote on last edited by
    #1

    I am using a contextmenuStrip in Treeview . The problem is When 1. Open Context menu strip by right clicking TreeNode. 2. Do not select any item in Context Menu Strip . 3. Select any TreeNode in Treeview . Now Context Menu Disappears. (This is fine) 4. Now press any keyboard Key . Nothing is working . The control is still with ContextMenuStrip popup menu even though it is has disappeared. How to solve this problem ?. How to disable the Key down event in ContextMemuStrip ? I am able to trap PreviewKeyDown event for ContextMenu but not able to diable Key Down event in Context Menu.

    G 1 Reply Last reply
    0
    • V Varad_Rajan

      I am using a contextmenuStrip in Treeview . The problem is When 1. Open Context menu strip by right clicking TreeNode. 2. Do not select any item in Context Menu Strip . 3. Select any TreeNode in Treeview . Now Context Menu Disappears. (This is fine) 4. Now press any keyboard Key . Nothing is working . The control is still with ContextMenuStrip popup menu even though it is has disappeared. How to solve this problem ?. How to disable the Key down event in ContextMemuStrip ? I am able to trap PreviewKeyDown event for ContextMenu but not able to diable Key Down event in Context Menu.

      G Offline
      G Offline
      Gareth H
      wrote on last edited by
      #2

      Varad_Rajan, What should happen if you press any key down?, Also, what event are you using to display the ContextMenuStrip? I don't quite understand what the problem is... Regards, Gareth.

      V 1 Reply Last reply
      0
      • G Gareth H

        Varad_Rajan, What should happen if you press any key down?, Also, what event are you using to display the ContextMenuStrip? I don't quite understand what the problem is... Regards, Gareth.

        V Offline
        V Offline
        Varad_Rajan
        wrote on last edited by
        #3

        Tnanks for your reply Gareth. I do not want anything to happen when I press Key down. I have added the contextMenuStrip in form at design time. I have displayed items in it and using the mouse click event for functionality. But when I press Key down event in context menu and when I go back to Treeview and press Key down the control is going to Contextmenu. It is supposed to go to Treeview. I am surprised why in keydown event control is going to Contextmenu when It has been closed . Hope you have got my problem .. Regards, Rajan

        V G 2 Replies Last reply
        0
        • V Varad_Rajan

          Tnanks for your reply Gareth. I do not want anything to happen when I press Key down. I have added the contextMenuStrip in form at design time. I have displayed items in it and using the mouse click event for functionality. But when I press Key down event in context menu and when I go back to Treeview and press Key down the control is going to Contextmenu. It is supposed to go to Treeview. I am surprised why in keydown event control is going to Contextmenu when It has been closed . Hope you have got my problem .. Regards, Rajan

          V Offline
          V Offline
          Varad_Rajan
          wrote on last edited by
          #4

          Adding one more to thread... When I do the above and press Keydown in Treeview the application throws an exception saying arithmetic underflow or overflow error? Do you have any idea of this ? Thanks, Rajan

          G 1 Reply Last reply
          0
          • V Varad_Rajan

            Tnanks for your reply Gareth. I do not want anything to happen when I press Key down. I have added the contextMenuStrip in form at design time. I have displayed items in it and using the mouse click event for functionality. But when I press Key down event in context menu and when I go back to Treeview and press Key down the control is going to Contextmenu. It is supposed to go to Treeview. I am surprised why in keydown event control is going to Contextmenu when It has been closed . Hope you have got my problem .. Regards, Rajan

            G Offline
            G Offline
            Gareth H
            wrote on last edited by
            #5

            Varad_Rajan, OK, i understand a bit better now. Like i said in my first post, whats the event your using to display the ContextMenuStrip? Regards, Gareth.

            V 1 Reply Last reply
            0
            • V Varad_Rajan

              Adding one more to thread... When I do the above and press Keydown in Treeview the application throws an exception saying arithmetic underflow or overflow error? Do you have any idea of this ? Thanks, Rajan

              G Offline
              G Offline
              Gareth H
              wrote on last edited by
              #6

              I have never had that error before, but a quick check on MSDN: http://msdn2.microsoft.com/en-us/library/6a71f45d(VS.71).aspx[^] * Integer arithmetic overflow either throws an OverflowException or discards the most significant bits of the result (see below). Integer division by zero always throws a DivideByZeroException. * Floating-point arithmetic overflow or division by zero never throws an exception, because floating-point types are based on IEEE 754 and so have provisions for representing infinity and NaN (Not a Number). * Decimal arithmetic overflow always throws an OverflowException. Decimal division by zero always throws a DivideByZeroException. What are you trying to do?, you'll need to show some code. Regards, Gareth.

              1 Reply Last reply
              0
              • G Gareth H

                Varad_Rajan, OK, i understand a bit better now. Like i said in my first post, whats the event your using to display the ContextMenuStrip? Regards, Gareth.

                V Offline
                V Offline
                Varad_Rajan
                wrote on last edited by
                #7

                I am not using any event to display the context Menu Strip. It is declared as private System.Windows.Forms.ContextMenuStrip DimensionModify; in class designer of form When I add it in visual designer. I am using DimensionModify.show() or DimensionModify.Hide() to display or hide the contextMenu .

                G 1 Reply Last reply
                0
                • V Varad_Rajan

                  I am not using any event to display the context Menu Strip. It is declared as private System.Windows.Forms.ContextMenuStrip DimensionModify; in class designer of form When I add it in visual designer. I am using DimensionModify.show() or DimensionModify.Hide() to display or hide the contextMenu .

                  G Offline
                  G Offline
                  Gareth H
                  wrote on last edited by
                  #8

                  Varad_Rajan, If you have added it to the TreeView1.ContextMenuStrip property in the designer, why do you need call Show() or Hide(), as its automatically done and you don't need to worry about that. Regards, Gareth.

                  V 1 Reply Last reply
                  0
                  • G Gareth H

                    Varad_Rajan, If you have added it to the TreeView1.ContextMenuStrip property in the designer, why do you need call Show() or Hide(), as its automatically done and you don't need to worry about that. Regards, Gareth.

                    V Offline
                    V Offline
                    Varad_Rajan
                    wrote on last edited by
                    #9

                    You are right Gareth. It automatically appears as you said. But in certain situations for functional aspect I need to show or hide it. But the problem comes when I press key down after I show the context Menu. The control after that for keydown always goes to context menu. Why is not coming back to Treeview for Keydown.

                    G V 2 Replies Last reply
                    0
                    • V Varad_Rajan

                      You are right Gareth. It automatically appears as you said. But in certain situations for functional aspect I need to show or hide it. But the problem comes when I press key down after I show the context Menu. The control after that for keydown always goes to context menu. Why is not coming back to Treeview for Keydown.

                      G Offline
                      G Offline
                      Gareth H
                      wrote on last edited by
                      #10

                      The only thing i can think of is that the context menu still has focus. So you when close the context menu, you need to set the tree view to have focus. Regards, Gareth.

                      1 Reply Last reply
                      0
                      • V Varad_Rajan

                        You are right Gareth. It automatically appears as you said. But in certain situations for functional aspect I need to show or hide it. But the problem comes when I press key down after I show the context Menu. The control after that for keydown always goes to context menu. Why is not coming back to Treeview for Keydown.

                        V Offline
                        V Offline
                        Varad_Rajan
                        wrote on last edited by
                        #11

                        My doubt is After the context menu is displayed, the context menu is still there even after I close it explicitly. When I minimize and maximize the form the keydown event is going back to treeview. But I am not able to achieve this programatically.

                        V 1 Reply Last reply
                        0
                        • V Varad_Rajan

                          My doubt is After the context menu is displayed, the context menu is still there even after I close it explicitly. When I minimize and maximize the form the keydown event is going back to treeview. But I am not able to achieve this programatically.

                          V Offline
                          V Offline
                          Varad_Rajan
                          wrote on last edited by
                          #12

                          I tried Gareth , focusing, activating treeview But still the keydown control goes to ContextMenu. I tried to Minimize and Maximize the form programatically to make context menu lose focus but it is not working. Thanks

                          A 1 Reply Last reply
                          0
                          • V Varad_Rajan

                            I tried Gareth , focusing, activating treeview But still the keydown control goes to ContextMenu. I tried to Minimize and Maximize the form programatically to make context menu lose focus but it is not working. Thanks

                            A Offline
                            A Offline
                            Anthony Mushrow
                            wrote on last edited by
                            #13

                            This is wierd. How about trying to disable, then enable the context menu. Disabling it should stop it doing whatever it is, that its doing. this.contextMenu.Enabled = false; this.contextMenu.Enabled = true; Unless of course re-enabling it straight away means that nothing actually happens. Don't know 'till you try i guess.

                            My current favourite word is: Nipple!

                            -SK Genius

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups