This project is read-only.

Context Menu causes keyboard shortcuts to fail

Topics: Developer Forum, User Forum
Apr 7, 2013 at 3:04 PM
Thanks for looking. I am a total newbie so please talk to me like a child :)

I managed to get everything in and working and made my own custom syntax file. However I still really don't know how to control and code Sci.

As an example, I'm using VB.Net Express and I have an editor made and working. I decided to add some of the keyboard shortcuts to my edit context menu at the top of the screen.

As soon as I did that the shortcut stopped working. For example, I added "Comment Selected" and set the short cut to Ctrl + Q. As soon as I did that the comment shortcut no longer worked.

I added a button and made it set focus to the editor and then send keystrokes but that really isn't a solution to keeping the keyboard shortcuts if I can't display them to anyone.

I would really appreciate it if someone could tell me how I get something like comment (Ctrl + Q) working on a context menu. I'm sure it's not as hard as I think it is but after 5 hours of searching I've given up. A VB.Net example would be really appreciated.

Thanks for your help.
Apr 11, 2013 at 11:45 AM
I'm not a VB programmer, so I can't write code for you and be sure that it works, but I've done similar things in my C# application. I know this isn't a direct solution, but a very good resource is this page. I think what you may need to do is set shortcuts on your Form.
Apr 11, 2013 at 7:07 PM
Well I can send key presses to the form to make the function work but I can't assign say the shortcut key to a menu item. I really want people to be able to use short cuts not have to press buttons to get all the features to work.

There has to be a way to do this. I can't believe all the people out there don't have context menus with short cut keys. I mean whats the use of having short cuts if you can't let people know they are there. I could make a pop up window showing what all the short cut keys are but I think that's a really bad solution.
Apr 11, 2013 at 7:33 PM
I don't have a clear picture of what you are trying to do. Context menus are usually pop up menus that get triggered on right click of the target control whereas main menus are located at the top of the screen.

It would really help to see what you are trying to do. Can you please upload an example project? If you create a new issue it allows you to upload an attachment.
Apr 11, 2013 at 7:45 PM
Edited Apr 11, 2013 at 7:49 PM
Sorry I thought I explained it pretty well.

You know at the top of your screen you have File, Edit, Tools..... Well I'm just trying to add short cuts to it. So lets say I type a new line in menu and call it "Comment". Once I do that I go to my properties window and assign the shortcut CTRL + Q. Once that is done ctrl Q no longer works at all in the editor. If I remove the shortcut it starts to work again.

So basically adding any menu item with a shortcut assigned to Sci stops that shortcut from working.

There's nothing to upload because I don't have anything. Assigning the shortcut stops them for working so I don't have them assigned. What I need to know is how to assign a short cut to menu item and have it work and not stop the default behaviour from working.

Hope that all makes sense.

What I did notice was, when made a button that sends the keys ctrl q it would work but only after I set focus back to the edit window. I don't think that's a clue though because assigning the short cut to the menu stops it from working completely.
Apr 11, 2013 at 8:59 PM
If you define a shortcut in a menu strip it will take precedence. The ScintillaNet never sees the keypress event. This is regular Windows Forms behavior, swap out ScintillaNet with a RichTextBox and the same thing will happen.

What do you do in your menu item's click event handler? Your solution may be as simple as adding
scintilla.Commands.Execute(BindableCommand.StreamComment)
assuming scintilla was a reference to your ScintillaNet control.
Apr 11, 2013 at 9:33 PM
I guess this is where the fun starts. The editor was the first thing I ever made in VB.net and first thing I made in about 10 years.

All I did was drag the scintillanet editor onto my form from my tools menu after adding the DLL to the project. I then just added a menu assigned the normal clipboard and exit codes to the menu items.

I never added a click event handler or really know how. Now of course the program is a bit more indepth with custom buttons to insert text into the editor and I redid an xml file to give custom colours to my own code but I didn't alter or add anything in the way of event handlers.
Apr 11, 2013 at 10:15 PM
The event you need to handle is
http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripitem.click.aspx

More in-depth event handling in general
http://visualbasic.about.com/od/learnvbnet/a/eventhandler.htm

I know that in c# the VS Windows Forms designer will automatically create an event handler if you double click the item in the designer. I don't know if it works the same way with VB.