Rename control methods in Windows Forms application - c#

I have just started coding in C#, and have been attempting to make a GUI application. I made a menu strip and wrote some code for one of the menu items. The method for clicking that menu item was automatically named "openToolStripMenuItem_Click".
In the properties I decided to change the name of the menu item from "open" to "save", but the method name remains the same, which is quite irritating. How do I get it to automatically adjust the method names when I rename a control?

This is not done automatically. A good way is to right-click the method name and use refactor + rename.

Related

Alter context menu for highlighted text in Windows10/11 [duplicate]

I'm trying to add a Windows Shell shortcut (right click context menu item) so anywhere in Windows, when I have text selected this item will appear. I cannot find the Registry item to alter/add or what to put there to get this to occur.
The selected text needs to also be passed to my application as an argument some how. I will be selecting some ID numbers, then manipulating those in the project.
Any assistance is greatly appreciated.
As far as I know, there is no way to create the shell extension which will allow you to inject into the any textbox's context menu.
The most you can do is to hook up the window creating API, filter out everything except context menu creation (WPF windows go down) and then do whatever you want to.

Deleting an item off of Windows Forms in both the Code.cs and Code.cs[design] properly

When I'm making a Windows form application, and I use the toolbox and drag an item onto the form, I get a nice tool on the form, like button, listbox, etc. When I double click on the button, listBox, etc it goes to the text code part where all the delegates are. Also known as the event handlers. But what happens when I want to delete an item on the visual part of the application (the Code.cs[design] part)? I select it, then right click it and then delete it. It's off the screen. But, the problem is with all the event handlers. They're still left in the text-based code section but I don't need them there at all, and they generate a whole bunch of errors because references are gone, etc.
So, basically, I'm asking someone on the forum how to completely get rid of a button, listBox, both the visual part of it in code.cs[design] and in the code.cs part? I don't want to go line-by-line in deleting junk, I want to get rid of the button/listBox and it's accompanying code in one fell swoop.
It will delete such an automatically added event handler. But only if you didn't modify it and left it untouched with no code added. Visual Studio will not delete code that you have written. The reason for that should be obvious.
If this happens a lot then you need to get a pair of scissors and cut the mouse umbilical cord. Design first, program later.
I can't be done and it shouldn't.
You first delete the visible control and after that you delete the code stubs.
The handler assignments in the Designer.cs are then being deleted with the visible control automagically, as they were created.
Just make sure to get the order right: first delete the controls then the code.
Unless you mix those up there is no need to ever edit the designer.cs file. The code may contain important stuff you wrote. Therefore is is not deleted by studio.
You create it, you delete it! Two steps, period.
PS: The code stubs are (unfortunately) added chronologically. It would be nice if they were grouped by the controls they belong to. If you are in doubt, you can always use the 'find all references' command to find those methods buried in the past..
If you have a code stub generated, delete the method. Once that's done, Click on your 'forms view' - you will have an error screen shown.
Click on the link, and it will being you to the designer view, with your cursor shown on a specific line. Delete this line of code. Having that done, you could then delete the physical element from your designer.

How to include windows right click menu in my application?

I have a desktop app which after taking input from the user displays a list of files and folder(using a ListBox).
I want that when the user right clicks on any item in the ListBox, the right click menu of windows explorer should display.
I know I will have to use P/Invoke for this, but I am unable to find any relevant information such as which dll I have to use or which function I have to call.
Can anybody help me with that?
So this question is very old but has no accepted answer. I dont think Visionstar understood the issue OP is having.
My understanding is that you have an application running, and you would like to add an option in the WINDOWS EXPLORER's right-click menu. Not in your own application's context menu.
I do not think you can achieve this within your own application, however, what you can do is add an item in the Windows explorer's context menu (nothing to do with your application, you can just do that in windows; see link below) that you can setup to call a little script you would make (literally a little batch file... but could be a .net app too). That little script can take care of warning you main application. By creating a text file, or json file in a hot folder, or some other mechanism you would have to come up with.
Adding an item in the windows' contextual menu:
How add context menu item to Windows Explorer for folders
If you need to deploy this to other PCs, you can make a add_menu.reg file to make it simpler. I'll let you Google that one, but I think it's as simpe as a right-click -> export key in your regedit.
You will need to code it yourself, there is no embedded way simply add a OS-Contextmenu to it,because you have programmed the listbox, so you have to append some contextmenu to the listitem-rightclicks
Here are examples/guidance for adding a context menu:
http://msdn.microsoft.com/en-us/library/aa984254%28v=vs.71%29.aspx
http://social.msdn.microsoft.com/Forums/windows/en-US/790cd8be-0ba8-4f10-95a8-c88f1023d6e7/how-can-i-create-a-rightclick-menu-i-c?forum=winforms

Add custom item to right click menu when user selects text

I want to add a custom menu item to the menu that appears when a user selects some text and right clicks. I searched a lot but did not get any answer. Maybe I did not put in the right keyword.
Is it possible to do this?
If this is possible, I want to do this for all applications in windows whenever the user selects text. Is there a universal way to do it or will have to write code specific to the application?
I am using C#.
I don't think you can do that universally in all windows apps. But it is certainly possible to do in your own app using a popup menu.
I've also tried a way to add an item to the standard ContextMenu and failed. From my point of view, the only solution is to set the TextBox's ContextMenuStrip property to an instance of the ContextMenuStrip class and implement both standard and your custom menu items. It is easy to mimic standard operation, since the TextBox class provides all required methods: Cut, Copy, Paste, SelectAll.
The universal way is basically writing a "custom shell extension".
There is an article on CodeProject about how to do this.
http://www.codeproject.com/Articles/174369/How-to-Write-Windows-Shell-Extension-with-NET-Lang
The other way to do this is to build this into your application. For example you might have a text editor and you'll want to highlight a word and get a definition for that word. To do this you'll need to implement a context menu.
The VERY BASIC concept is detailed over on CodeReview.StackExchange.
https://codereview.stackexchange.com/questions/3983/c-programatically-creating-context-menu

Controls on WinForm not modifiable in Designer

I've inherited a project that has been modified in a way that is beyond me to undo. Every single control on the form is not modifiable in the designer except through the Properties window and each control has an icon in the area below (see image) in the section usually reserved for non-visible items (e.g. DataSource). How do I undo this and return the designer to a usable version without wiping it all out and starting over?
Could the controls be locked? I have run into legacy code in which the programmers have locked every single control, meaning you cannot move or resize them in the designer. If so, select them all and change the Locked property to false (you should also see a padlock in the designer when you select them, if they are locked.
If not, well maybe you can create a new dialog/form and copy the controls unto it and see if that clears things up. Another trick could be to add a second instance of the user control(s) to see if the newly added control works as expected. If so, go through the code and point all events/logic to the new control (tedious yes, but may work).
Also, you can never edit individual sub-controls of a user control in the designer for the form/control where you instantiated the user control. You must go to the designer of the user control to edit individual (sub)controls of a user control.
If the Infragistics controls are shown in the Component Tray, than there might be version differences. What you could try is to open the licenses.licx file and remove the content from there. Do you have an Infragistics controls installed on your machine? Are there any difference after setting the "Specific Version" property of the Infragistics assemblies to "false"?
Is this happening only in your existing project or the same behavior is reproducible in a new project as well?
You have to load the dll that contains the controls you can't modify in the designer.
the steps are:
right click in the ToolBox in visual studio designer (on General for example).
select Choose Items...
after a while vs load items press browse and select the dll
interested than the componet should appear in the grid. Do this for
all the dll that contains the controls you are interested.
-Make sure you have checked the component (use filter text box if you
have a lot of component loaded).
press ok.
Now you should be able to move controls in designer.
I have also seen behavior this when a user control or form is incorrectly flagged as a 'Component'.
Some manual hacking of the .csproj file may be the answer then. Open the project file in a text editor, and find the references to your control. If you find a subtype defined as:
<Compile Include="MyControl.cs">
<SubType>Component</SubType>
</Compile>
The forms designer will interpret it as such. You can change the 'SubType' to 'UserControl' to fix it.

Categories