473,762 Members | 7,330 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ContextMenuStri p prevents keys from working in custom control!

WebDunce
15 New Member
hey all,

i'm building a custom control. it contains a treeview and a context menu. each tree node's context menu property is set to the control's context menu.

it works good...except.. .

if after right-clicking on a tree node, if you decide NOT to use any of the options and click OFF of the tree view...the context menu disappears (great!) but then the control no longer seems to process key strokes. it's like the context menu, tho no longer having focus, is still catching the key strokes.

if i right-click on another node and select an option from the context menu...the keys start working again.

any ideas on how to get the keys working if i pull up the context menu but do NOT select an option?

i feel like the answer to this puzzle must be very simple, for some reason...like a property on the context menu i need to set...or an event i need to handle.

thanks all.
Mar 17 '07 #1
5 2469
WebDunce
15 New Member
further testing confirms that indeed if a menu item on the context menu is selected, my custom control regains control of key input, but if i simply click off of the context menu, then the context menu retains control of the key input.

I tested this by overriding the ProcessCmdKey sub in the context menu object. i had it display a messagebox whenever it fired. While the menu displays, it fires. If a menu item is selected, the menu disappears and my custom control can use the keys normally. but if i simply click off the menu, the menu does disappear but key strokes continue to cause the context menu's ProcessCmdKey sub to fire.

Whether i click on or off the menu, in both cases it disappears and loses focus (confirmed by messagebox)...s o i cant see why it is retaining control of the keys!

I've looked at so much of microsoft's documentation on the ContextMenuStri p, but nothing seems to address this issue directly (i.e., nothing says: "caution: if you dont do xxxxx, then your contextmenustri p will not release control of the keyboard input if the user fails to select an item, and this will annoy you to no end...")

pressing escape, while the context menu is visible -- or after clicking off it -- will return control of keyboard input to my custom control.
Mar 18 '07 #2
WebDunce
15 New Member
okay, i've reconstructed a highly simplified version of my program...a form, a usercontrol with a treeview and nodes, and a context menu....

the context menu is working fine on the simplified version...that let's me know the issue is with my code...not with the .net objects themselves or any of their properties...of course there's no way i'd expect anyone to find the problem in my code...i wouldn't even know what portions to post...but at least i no longer think i am overlooking some property or setting or event or whatnot on the context menu (nor am i any longer considering that the context menu control is buggy)...

if ever i find the problem i'll try to remember to post the answer...i'm sure everyone is just dying to find out. ;)
Mar 18 '07 #3
kenobewan
4,871 Recognized Expert Specialist
I'll be interested. Don't know how to solve your problem but simplifying and debugging is the right way to go.
Mar 18 '07 #4
WebDunce
15 New Member
I'll be interested. Don't know how to solve your problem but simplifying and debugging is the right way to go.
hi kenobewan,

thanks for your interest. i have found the problem!

right-clicking on any of my treeview's tree-nodes fired the sub below...

Expand|Select|Wrap|Line Numbers
  1. Private Sub tvwMenu_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles tvwMenu.NodeMouseClick
  2.         ' if we click the right mouse button...
  3.         If e.Button = Windows.Forms.MouseButtons.Right Then
  4.  
  5.             ' a bunch of statements which define
  6.             ' the options that should appear
  7.             ' on the ContextMenuStrip
  8.  
  9.             ' show the context menu
  10.             e.Node.ContextMenuStrip.Visible = True
  11.         End If
  12.     End Sub
  13.  
the problem is the line:
Expand|Select|Wrap|Line Numbers
  1. e.Node.ContextMenuStrip.Visible = True
  2.  
apparently the contextmenu knows it is supposed to show itself on the right-click of the associated object...so not only is the statement simply uneccessary...i t also, for some unknown reason, causes my issue. when this line is removed...all is well.

good bit of detective work there...hours and hours and hours...over such a small thing!

--William
Mar 20 '07 #5
WebDunce
15 New Member
on the bright side...it is not the complexity of my code in general but is actually what i had originally thought...my misuse of the ContextMenuStri p object.
Mar 20 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1473
by: Nagachandra Sekhar Grandhi | last post by:
I placed a combobox control on User control and this user control was placed on a form and I tried to catch the keys pressed on that combo box, but I am unable to do it. I set the property of keypreview to true. But when I do the same for text box it is working fine. After that I placed the combo box control on the form itself and done the same then also I wasn't able to get the keys pressed on that control. Is this problem with the...
4
3293
by: boopsboops | last post by:
Hi thescripts people, I hope I'm in the right forum for Visual Basic Dotnet (VS 2005). I am trying to make a custom control in which you can nudge a point around using the arrow keys. Actually, the control is meant to be a simple drawing program. To test it out I have put the control on a Windows form which also contains several buttons. I have added a KeyDown event handler to the custom control (see code below). It responds fine to keys...
7
7601
by: Dave | last post by:
How do I get my ContextMenuStrip to receive key down preview events? I have the event hooked but I don't see the key strokes in the event? Dave
5
15495
by: =?Utf-8?B?cHJvZ2dlcg==?= | last post by:
I've written an application that can minimize to the tray and can reappear if you double click on the icon in the tray (ShowInTaskbar is set to false). I've also created a ContextMenuStrip (Visual C# 2005) so that you can write click on the icon in the tray for options. I then captured the event for mouse clicks on the Notify Icon so that I could detect the left click event and then display the contextmenustrip using either:...
3
8990
by: ommail | last post by:
I have two RichTextBox controls on a form, and single ContextMenuStrip control which serves for both textboxes. I need to determine which RichTextBox control invokes an event handler in ContextMenuStrip. So I use that code: private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
1
5941
by: =?Utf-8?B?TGVudXNpYQ==?= | last post by:
In my program I dynamically create treeViews and dynamically add nodes to them. To each node I attach ContextMenuStrip which suppose allow delete selected node e.t.c. How from inside click event handling function to find which node was selected? sender is set to ToolStripItem clicked.
7
7852
by: Joe Cool | last post by:
Let's say I have a Treeview control on a form. Each leaf node in the Treeview has a ContextMenuStrip, each with one ToolStripMenuItem, and all ToolStripMenuItems Click event is handled by a comment event handler. How do I determine which Treeview Node signalled the menu event in the common event handler?
1
5117
slapshock
by: slapshock | last post by:
Good day, please help me on my problem.... i want to create a context menu strip on run time but i got this error, please help me, i tried to search on the net but i cant fine any solution there... my code is: Imports System.ComponentModel.CancelEventArgs Public Class VinteryBase Private m_New As Boolean Sub CreateMenu() Dim mnuItem As ToolStripMenuItem
2
3445
by: eBob.com | last post by:
I've been working on an app which has an array of RichTextBoxes. And I have a context menu for the RTBs. The context menu has two levels; the first level has two items, "Load Sample Text File" and "Insert Row >"; the "Insert Row >" item on the first level invokes, if that's the right word, a second level which has two items, "Above" and "Below". This all worked when it was a ContextMenu. But I am trying to change it to use the new menu...
0
9378
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9989
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9927
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9812
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8814
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5268
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.