473,473 Members | 2,097 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

VB.NET - Menu Shortcuts

Hi all,

I have this problem I have a menu structure in my VB.NET application
that is about 4 levels deep. I need an CTRL+key access to the 3rd
level so that if user press CTRL+key the 3rd menu rolls out

The standart code :

myMenuItem.Shortcut = Shortcut.CtrlA

does not work it only works for the final item in the menu that has an
event handler but this is what I need to do...

Anybody any suggestions?
Nov 21 '05 #1
2 2652
On 2 Sep 2004 01:52:04 -0700, pa***@pobox.sk (Brano) wrote:
Hi all,

I have this problem I have a menu structure in my VB.NET application
that is about 4 levels deep. I need an CTRL+key access to the 3rd
level so that if user press CTRL+key the 3rd menu rolls out

The standart code :

myMenuItem.Shortcut = Shortcut.CtrlA

does not work it only works for the final item in the menu that has an
event handler but this is what I need to do...

Anybody any suggestions?


AFAIK a main menu cannot be opened directly from code (though SendKeys
might help, or you could send windows messages simuating mouse clicks), but
you can clone the submenu you want to open into a context menu.

It's not as pretty a solution as opening the real thing, as the
higher-level menus aren't shown.

Suppose the submenu you want to open is called mnuX, and you want to assign
key F8 to it. Instead of setting F8 as shortcut key, set the form's
KeyPreview property to True, and code it like this:

Private Sub Form1_KeyDown(ByVal sender As Object, ....
If e.KeyCode = Keys.F8 Then
Dim cx As New ContextMenu
For Each mi As MenuItem In mnuX.MenuItems
cx.MenuItems.Add(mi.CloneMenu)
Next
cx.Show(Me, New Point(0, 0))
e.Handled = True
End If
End Sub

You don't need to call AddHandler for the cloned menu items, they inherit
the handlers of the originals.

Nov 21 '05 #2


Hi I have tried your code but It does not seems to even pickup pressing
of F8 key as an event... I mean if I put the code under Form_KeyDown
Replace what is after Then statement with msgbox("F8") run it and then
press F8 nothing happens...

and the next thing my menus are build from the code like this :

'# creating variables to hold default menu items
Dim TestsItem As New MenuItem
Dim AddTestItem As New MenuItem
Dim DeleteTestItem As New MenuItem
Dim MicrobiologyItem As New MenuItem
Dim ChemistryItem As New MenuItem
Dim GroupTestsItem As New MenuItem

'# assigning them text
TestsItem.Text = "&Tests"
AddTestItem.Text = "&Add Test"
DeleteTestItem.Text = "&Delete Test"
MicrobiologyItem.Text = "&Microbiology"
MicrobiologyItem.Shortcut = Shortcut.CtrlA
MicrobiologyItem.ShowShortcut = True
ChemistryItem.Text = "&Chemistry"
ChemistryItem.Shortcut = Shortcut.F9
ChemistryItem.ShowShortcut = True
GroupTestsItem.Text = "&Group Tests"
GroupTestsItem.Shortcut = Shortcut.F11
GroupTestsItem.ShowShortcut = True

'# adding them to the menu
thisMenu.MenuItems.Add(TestsItem)
TestsItem.MenuItems.Add(AddTestItem)
TestsItem.MenuItems.Add(DeleteTestItem)
AddTestItem.MenuItems.Add(MicrobiologyItem)
AddTestItem.MenuItems.Add(ChemistryItem)
AddTestItem.MenuItems.Add(GroupTestsItem)

there is more code that populates

MicrobiologyItem
ChemistryItem
GroupTestsItem

with loads of another stuff from Database (about another 50
items) none of them has any more subitems
What will the code look like to clone every item from MicrobiologyItem
??

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3

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

Similar topics

7
by: cefrancke | last post by:
I cant seem to find a straight answer on the following. I want to programmatically hide all menus except a basic custom report menu (during report preview) and right click pop-up A-Z sorting on...
4
by: Aaron Queenan | last post by:
How can I use the designer to add a context menu to a class which inherits from a control, e.g. treeview, without adding the context menu to a form? For example, to add a context menu with...
7
by: news.microsoft.com | last post by:
I am in the process of porting a program from DOS to VB.NET. I was given the direction of recreating the feel and functionality of the menu system from DOS. The system will not have access to a...
2
by: PadPad | last post by:
How to create the menu shortcuts for the menu item.
2
by: Pad | last post by:
How to create new shortcuts key in order for the user to access it. for example I want to create ctrl+f for the File menu. How can I do this???
7
by: Dominique Gratpain | last post by:
Hi, Two questions about menu and shortcuts (in WindowsForms) : 1) I create a main menu with two items in menu bar : &menu 1 and m&enu 2 I see the accelarator key (m underline for menu 1 and...
0
by: Fredrik Melin | last post by:
I dont know if its the framework or the fact that I am using MenuStrip nowadays but If you have a textbox highlighted (active control), menu shortcuts dont work anymore. My textboxes is readonly...
0
by: Dave Harris | last post by:
After switching cultures for a thread, the Menu shortcuts are still showing the English word shift (as in Ctrl+Shift+M instead of Ctrl+Maj+M in French). Running this on a French version of windows...
0
by: dinka | last post by:
Hi, I create a form with a main menu and assigned some shortcuts to the menu items, the form also contains a textbox, when the focus is in the text box the menu shortcuts like CTRL+R are not...
2
by: andylotus | last post by:
Hi People I have a WinForm program. The UI contains a ToolStripDropdownButton, which is associate a list of menu items of ToolStripMenuItem, created dynamically. Upon different scenarios of user...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.