7

I want to "find all references" to a control on my windows form (in designer mode). This is the painful procedure I currently use:

  1. Click on the control
  2. Goto the "Name" in the property sheet
  3. Copy the name of control in clipboard
  4. Perform a find in all files, pasting the name of control to find.
  5. Click on an arbitrary result then right-click and then "find all references"

I wonder if I miss something or there is really no way to perform such operation in simpler ways. Also I recently installed Resharper (for sake of other features).

Please tell me if there is any built-in way in VS or any methods provided by Resharper or its plugins to ease such operation,

I use VS 2010 SP1 C# and Resharper V7.0.

EDIT: It is much appreciated to mention whether your whole proposed solution or portions of it are based on VS, or Resharper when answering. (Because I installed Resharper very recently and not gone deep in its features yet), thanks a lot.

Acknowledge & Conclusion: Thanks to thersch: His answer is like a full-article and very informative for community. Thanks to wal: He pointed two delicate tips (sorted-list view, skipping name look up). Thanks to both of you: You complemented the missing parts together.

Current Status: I reported the issue to developement and have requested this as a feature to be implemented in later versions of the resharper, visit the link below for tracking the current status of the issue from the tool vendor :

https://youtrack.jetbrains.com/issue/RSRP-429747

DISCLAIMER: I have no affiliation with the tool / vendor, just a user.

2
  • 1
    I have updated my answer with informations about which tool owns which feature. See last section ("Which shortcuts are VS and which ones are ReSharper related?").
    – thersch
    Commented Aug 21, 2012 at 12:16
  • @thersch Thanks for that addition. (Because actually my key settings was differing from that of yours, for example, I had to press Alt+Ctrl+0 to view code from designer). Now, I changed my key bindings to C#2005 and that is now the same as yours=> F7 shows the code. Tnx again for clarification of shortcut sources.
    – F.I.V
    Commented Aug 22, 2012 at 4:33

2 Answers 2

5

F7, (Ctrl+[)+, Shift+F12

  • F7 for viewing code
  • Ctrl+[ to navigate to a containing declaration until you reach the class name
    (Press it several times or just keep keys down until class name is reached)
  • Shift+F12 to show all references of that Control class

Again in detailed steps:

Assumed you have open the Design View of a forms control (MyControl.Designer.cs).

  1. F7
    (You don't need to select control before.)
    => Code file MyControl.cs is open.

  2. Set cursor on control's class name by:

    • selecting with mouse or
    • Ctrl+[ if you are below control's class declaration or
    • Alt+Down if cursor is above control's class declaration or
    • Alt+\ and select first class name.
      (Control's class name should be the first in all Forms controls code files.
      Alt+\ lists all members in real, non-alphabetical order (at least in my ReSharper 5.1.3))
      .
  3. Shift+F12
    => lists all usages

  4. Shift+F7
    => switches back to Design View

or

F7, select control in File Stucture window, Shift+F12

If you have already File Structure window (Ctrl+Alt+F) open (I have it always open.) switch to code view by F7, click there control's class name and press Shift+F12.

Again in steps:

Assumed you have open the Design View of a forms control.

  1. F7
    (You don't need to select control before, just have focus on Design View window.)
    => Code file MyControl.cs is open.

  2. Open File Structure window (Alt+Ctrl+F)

  3. Select control in File Structure window by:

    • selecting with mouse or
    • Ctrl+Pos1
      (Control's class name should be the first in all Forms controls code files.)
      .
  4. Shift+F12
    => lists all usages

  5. Shift+F7
    => switches back to Design View

Which shortcuts are VS and which ones are ReSharper related?

VS: F7, Shift+F7
ReSharper: Ctrl+[, Shift+F12, Alt+Down, Alt+\, Alt+Ctrl+F

6
  • The second method would be interesting if the file-structure window could list the elements in sorted alphabetical order (it didn't seem to have such option at first glance). Anyhow, switching between the designer and code is necessary and the copy-paste occurs virtually in human memory;) [instead of clipboard]. Thus you still have to: 1. Click on the control 2. Goto the "Name" in the property sheet 3. Memorize the name of control in your mind then go to the (*.Designer.cs file) 4. Find the memorized name in file-structure window 5. Then find usages to that name
    – F.I.V
    Commented Aug 21, 2012 at 9:37
  • u dont need your step2, see my answer
    – wal
    Commented Aug 21, 2012 at 9:46
  • @AliFakoor I see: it is neccessary to switch to code file before File Structure window shows Control's code. My earlier test did work and now I cannot reproduce it, sorry.
    – thersch
    Commented Aug 21, 2012 at 10:58
  • @thersch No problem. You are right. I saw the inconsistency as well: Well, sometimes when I switch to other code the file-structure still shows the structure of the previous file!. This may have been your case when you previously have switched to *.Designer.cs and again to code (while the designer structure being still being shown)
    – F.I.V
    Commented Aug 21, 2012 at 11:26
  • @thersch excuse me, I have difficulties with step 2 "Set cursor on control's class name". What is exactly meant by class name? Do you mean the variable name identifier (eg: textbox1)?. As well in this case it seems necessary that "myfile.Designer.cs" be open instead of "myfile.cs" (which is open by F7). Sorry, I think we have different POV about controls. I mean "Windows Common Controls" as found under ToolBox which you can put on your form. Hence in this case the "class name" of control (e.g: System.Windows.Forms.TextBox) should not matter much in the process.
    – F.I.V
    Commented Aug 22, 2012 at 5:46
1

I don't think you need step 2) Goto the "Name" in the property sheet

You can just click on the property and its name will be shown in the top combo box.

Assuming you have Resharper installed and you have selected the control in the designer you can then do the following:

1) F7 (go to code)
2) Alt + \ (List members alphabetically, start typing in this dialog to filter or scroll to the one you want, you dont need to type the complete name)
3) Shift-F12 (once youve made a selection from step 2)

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.