473,729 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ 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.Shor tcut = 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 2670
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.Shor tcut = 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(B yVal sender As Object, ....
If e.KeyCode = Keys.F8 Then
Dim cx As New ContextMenu
For Each mi As MenuItem In mnuX.MenuItems
cx.MenuItems.Ad d(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 MicrobiologyIte m As New MenuItem
Dim ChemistryItem As New MenuItem
Dim GroupTestsItem As New MenuItem

'# assigning them text
TestsItem.Text = "&Tests"
AddTestItem.Tex t = "&Add Test"
DeleteTestItem. Text = "&Delete Test"
MicrobiologyIte m.Text = "&Microbiol ogy"
MicrobiologyIte m.Shortcut = Shortcut.CtrlA
MicrobiologyIte m.ShowShortcut = True
ChemistryItem.T ext = "&Chemistry "
ChemistryItem.S hortcut = Shortcut.F9
ChemistryItem.S howShortcut = True
GroupTestsItem. Text = "&Group Tests"
GroupTestsItem. Shortcut = Shortcut.F11
GroupTestsItem. ShowShortcut = True

'# adding them to the menu
thisMenu.MenuIt ems.Add(TestsIt em)
TestsItem.MenuI tems.Add(AddTes tItem)
TestsItem.MenuI tems.Add(Delete TestItem)
AddTestItem.Men uItems.Add(Micr obiologyItem)
AddTestItem.Men uItems.Add(Chem istryItem)
AddTestItem.Men uItems.Add(Grou pTestsItem)

there is more code that populates

MicrobiologyIte m
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 MicrobiologyIte m
??

*** 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
6899
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 datasheets (for subforms). I would like to do this on startup of the application. To be clear:
4
14187
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 "Select All" and "Clear Selection" to a checked list box? Thanks, Aaron Queenan.
7
1199
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 mouse so it will (read must) all be done through Arrow/Enter keys. The way I'm planning to attack this right now is to use Graphics.DrawString & Graphics.FillRectangle in the Form.Paint method to duplicate the look and feel of the DOS menus. ...
2
1081
by: PadPad | last post by:
How to create the menu shortcuts for the menu item.
2
1007
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
1208
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 e underline for menu 2) only if i strike the alt key. If I don't use alt key, never i see these accelerator keys. Is it possible to see these accelerator key without to strike alt key ?
0
858
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 but enabled (so they are white in the background) CType(Item, TextBox).ReadOnly = True CType(Item, TextBox).Enabled = True CType(Item, TextBox).CausesValidation = False CType(Item, TextBox).BackColor = Color.White
0
1108
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 doesn't seem to act any better. What ultimately controls the display of the menu shortcut string? .NET, the OS, the keyboard attached? It doesn't seem to be the keyboard, other applications like windows media play show Maj just fine in the...
0
1156
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 working... Help.... Thank you, Dina
2
7078
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 operations, the DropdowButton need to clean up all its menuitems, and create new ones. Here the codes: //////////////////// Void CreateForEmail()
0
8917
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9426
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
9281
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
9200
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,...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
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...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2163
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.