How to add a button to Visual Studio Intellisense - c#

I would like to add a button to the top of the list of options returned by Visual Studio's IntelliSense. When the button is clicked, my custom code will be executed (which will, among other things, cause a popup to appear).
I call it 'button' because when the user click the item, I want a popup window to appear, as opposed to the normal IntelliSense action of completing the user's input.
Eg When we input a class name into the text editor, normally the static properties and static methods will appear in IntelliSense. But I want to add another item to the top of that list.
This item should appear at the top of the IntelliSense list, no matter what input/content caused IntelliSense to appear. The item will never change.
Is this possible, and if so, can you provide some direction as to how I should achieve this?

1) In a C# or VB project, open a code file and put the cursor where you want to insert the code snippet.
2) Bring up the code snippet menu in one of three ways:
Press CTRL+K, CTRL+X.
On the Edit menu, point to IntelliSense, and then click Insert Snippet.
Right-click the mouse and then select the Insert Snippet command on the shortcut menu.
3) Select the code snippet from the code snippet inserter and then press TAB or ENTER, or double-click the snippet.

In the IntelliSense property page, clear text box options or check box options for IntelliSense features that you do not want:
Show completion list after a character is typed
Committed by typing the following characters
Committed by pressing the space bar
IntelliSense pre-selects most recently used members applies to IntelliSense for Most Recently Used Members
For more information, see IntelliSense, C#, Text Editor, Options Dialog Box

Related

TAB highlights next word instead of indenting

When formatting code in Visual Studio 2019 I cannot indent the code with TAB key to line up parts of my code. I know in VS Code there is "Toggle Use of Tab Key for Setting Focus" - however, I could not find this in Keyboard options. Instead it highlights next segment of the code, e.g. variable name.
How do I get TAB to indent my code normally again?
Screenshot showing the highlighting. Happens every time after pressing tab after accessor keyword:

Adding control event methods from the code window Drop downs always go to bottom, can this be changed

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.

Where in Visual Studio 2012 did Page Controls and Events goto for codebehind?

I can't for the life of me figure out how to do something that I did forever in VS2008 and earlier with VS 2012.
When creating a web application, throw some server side controls on the page, then goto the codebehind and at the top of the code editor were 2 dropdowns. The one on the left displayed the page and controls on the page, selecting one of them say a GridView, would then display the Events for that control in the right side dropdown. So I could double click on it and create one of the events without remembering and typing the event in code.
In my VS 2012, the left only displays the Page (big help) and no controls. With that selected, the right dropdown displays controls, but selecting it only loads up the designer for that page and the entry for that control.
Is it a setting I don't have set, or how and why is this changed, how can do this again in VS2012?
It is in the properties window, but you have to click on the lightning bolt icon.
You can re-enable the events navigation bar at the top of code behind files like this:
1) From the Tools menu select Options
2) From the options on the left select All Languages
3) From the options on the right, click the checkbox next to Navigation Bar then check it again.
It is important to switch it off then back on again.
This will override your development environment settings and will force the Event Navigation Bar to appear at the top of all text editors.
Double-click on control (button) in Design vew to create a handler for its Click event.

C# - Menu Strip Query

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.

Custom User Control in C#...Right Click Menu to Copy Text (Java Developer learning C#)

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.

Categories

Resources