I have two questions regarding the windows form menu strip:
1. How to force the form to always show the helper keys?
Currently the letter underlines are displayed only if the Alt key is pressed.
2. What is the command to cause a menu to drop down?
Usually a menu drops down after the user clicks the menu button or navigates it with the keyboard, but I want to cause a menu to drop down by pressing an interface button and I can't figure out how to do it. I tried fiddling the DropDown property, but it didn't help.
With ToolStripMenuItem there are three properties you need to look at:
ShortcutKeyDisplayString
ShortcutKeys
ShowShortcutKeys
Although the three apply to the root menu item, say File or Help, you will not be able to see the short cuts, however you should be able to enable the ShortcutKeys, set ShowShortcutKeys to true and without modifying ShortcutKeyDisplayStringhave them appear next to sub ToolStripMenuItem's.
The method you are looking for on ToolStripMenuItem is ShowDropDown(), executing this method will drop down the menu.
Example:
((ToolStripMenuItem)FileMenu.Items[0]).ShowDropDown();
AFAIK, it is not easily possible to do that in C#. The easiest way is to change the Windows settings. On Windows 7:
Go to Control panel
Ease of Access Center
Make the Keyboard easier to use
Check Underline keyboard shortcuts and access keys.
Related
In the Visual studio IDE, i like to make regions to group functionality.
when I go to add a new code sub for a control event, by using the drop downs at the top of the code window and pick a control event that has not already been added.
it adds it to the bottom of the code window and I have to copy and paste it to move it back where I want it (at my current caret position).
Is there any way to make these generated control event methods insert at the current caret position instead of the bottom?
To clarify an example would be in the middle drop down box select Button1 in the right drop down box select the Click event.
if this is not a setting does anyone know of an addin that will accomplish this.
I couldn't seem to find a setting for this in the visual studio options (there may be one, but where)
Good question!
This is very annoying behaviour. Would be good to find an option for this, or get it sorted by Microsoft.
I have multiple controls on one form,and when i select some value from combo box(for example 1) next control became enabled, else next control stay disabled.
Problem is that if i just press 1 and tab, after that next control became enabled, but program jump over it just like control are still disabled, and tab control selecting next control.
I need to find way how to tab check is control become enabled and go on this control,and if control are still disabled that go on next enabled control.
Thanx
You created a mousetrap for the user, very hard to escape from. Technically you can handle the keyboard navigation by trapping the Tab key before it can be used to navigate but the user still has an unsolvable problem when he wants to use the mouse to change the focus. He has nothing decent to click on.
You'll need to re-think your UI design. One possible solution is to change the ComboBox's DropDownStyle to DropDownList. Which ought to be pretty appropriate if you use its selected item to enable other controls, there should only be a limited set of valid selections. If that's not what you want then you need to do something drastic. Not necessarily limited to hiding controls instead of disabling them.
This is probably caused by the event of the combo-box you using to control your flow.
The "Changed"/"Value changed" events in most languages fire up after the control has lost focus.
You forgot to add a tag for the UI technology you are using.
If you are using WinForms, then you can try to execute the SelectNextControl method on your control that the user just edited. This will find the 'next' control for you, and activate it.
Lets assume it's winforms (playing with disabled/enabled like this in wpf is.. against mvvm rules).
Firstly, ensure what tab order/index of your controls is ok. To test, if they are all enabled, then pressing Tab should go through them in the right order. This can be seen easily
Next thing is to choose one of many possible solutions, to make 1,Tab to work:
disable Tab key navigation at all;
make controls to pass control (focus) to specific control (making tab order irrelevant);
use SelectNextControl (work best for custom controls, which when will support that tab-flow schema);
prevent focus changing, do all logic, change focus (theoretically).
I'm currently trying to disable some buttons on the menu bar in word 2k3 but I have no clue on how to do so, from what I can find online it seems that i need to call the function "EnableMenuItem" from the user32.dll but it doesnt seem to work. Are there any other options available? I want to disable copy/paste/cut without the use of macros to intercept the calls.
thank you all for your help :)
Gonçalo
You'll have to iterate through the app.commandbars collection to find the specific commandbar (in this case,the EDIT MENU) and then interate through the commands to find the specific menu items, then you should be able to hook the click events, or disable the buttons (CommandBarButton objects have an ENABLED property you can set, I believe you can also set VISIBLE on them).
Be aware that in different languages, the Caption can change, so it's best to key of the ID property.
Here's a post of how to get those names and ID's
http://support.microsoft.com/kb/243988
In my application I have dropdown list with several items. I'd like to show a context menu when the user clicks the right mouse button on a dropdown item. Is this possible? And if it is possible, how?
It is possible but not easy. The ComboBox dropdown is a native ListBox that is created on-the-fly. To get the handle of that list box, you have to send the CB_GETCOMBOBOXINFO message in the DropDown event. Check my answer in this thread to find out how to do this.
The iceberg that is likely to sink that Titanic is that the dropdown automatically closes as soon as it loses focus. Which will happen as soon as you display the context menu. Nothing you can do about that.
Consider a different approach, you could use an actual ListBox that you make visible when the user clicks a glyph that looks like an arrow next a TextBox.
Not possible easily. No hover or right-click event messages are being sent when the combobox is expanded.
You can see this is the case when using Spy++.
I think the easiest would be to change to a listbox if your scenario allows you to do that.
As Wim said in his post, there's not a direct way to do this because the messages you want aren't fired.
As a comprise, you could try setting DropdownStyle=Simple; on the Combo and
shrink the scroll region to show a single line:
http://img34.imageshack.us/img34/1695/49557147.jpg
If you assign the Combo a context menu, it will open when the scroll region is right-clicked. You'd probably have to figure out what item was right-clicked. But as other have said, this doesn't sound like a standard Windows way or an intuitive use.
Or how about a modal dialog that you could bring up from the Combo's context menu? On the dialog, you could have a list that the user could select from and a Delete button to delete the selected item(s).
Since MenuItem doesn't have a ContextMenu property it isn't as easy as it is with many other controls. You'll probably need to capture the right-click event and then position and show the context menu manually.
Two caveats though:
The combobox list will close when the
list loses focus, so it may close
when the context menu is shown
leaving the user unclear as to what
they clicked on (not 100% sure on
this, since I haven't written the
code to test.)
More importantly though I would argue
that this is a poor UI choice, I
can't think of any real world
applications I've used that have
context menus on menu items, so it
wouldn't be very discoverable for the
end user. Plus context menus should
be just for quick access, they
shouldn't be the only way to access
functionality. Are you going to be
able to expose these functions
through other means as well as the right-click menu?
You could do it manually, by capturing the event on the form, but consider making a nested menu instead. If your combobox items have menus of their own, combobox probably isn't the right choice.
For those asking "Why?" or saying they've never seen a combobox with a contextmenu; Look at any web browser's favorites dropdown. You can right click and delete, edit, or go to the entry in current tab, new tab, or new window.
I also could not get an actual contextmenustrip to show, so I made a menu with a small borderless form and call with:
Private Sub FavoritesBar_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles FavoritesBar.SelectedIndexChanged
FavIndex = FavoritesBar.SelectedIndex 'FavIndex is declared as a public string.
Dim Loc As Point = New Point(MousePosition)
FavMenu.Location = Loc
FavMenu.ShowDialog()
End Sub
With a homemade contextmenu, be sure to add "me.close" at the end of each sub as well as the me.mouseleave event.
I'm working on a custom user control that essentially displays a name value pair (name is on a black background, value on a white). I have my control displaying correctly, even showing up in Designer and on my build page.
What I'd like to do from here is have the ability to right click on the user control and have a menu come up that has a "Copy Value" option, that when selected will copy the value in the "value" part of the user control to the clipboard. What is the best method of approach?
I'm not sure where to start since most of the documentation on user controls I've found deals with displaying the control, not necessarily interacting with it. Additionally, since I'm still learning C#, I might have left out an important part of my problem in this question, so please point that out if it's the case.
I'm using Visual Studio 2008 (if that matters).
Examine the ContextMenu control and the ContextMenu property of other controls. By assigning a ContextMenu control to the ContextMeny property of another control, you will have the right-click->popup menu wiring done for you. Then you only need to implement the click event of the different menu items in the context menu.
Then you can use the Clipboard.SetText (as suggested by BFree) to set the desired value to the clipboard.
Add a ContextMenu to the control. The, hook into the MouseClick (or MouseDown, whichever works better) event and if it's a Right-Click, then call show on the ContextMenu (there are a few overloads, try to mess with them see which works best for you). Then, in the click event of your context menu, just call Clipboard.SetText(...) to set the value to the clipboard.