views:

117

answers:

3

I saw a similar question asked and answered for ASP.net here http://stackoverflow.com/questions/484327/how-do-i-prevent-visual-studio-from-renaming-my-controls

But I am trying to prevent this while writing a Windows forms app in VS 2008 using c#. I want to copy/paste a ton of controls without them being called Checkbox1 etc. I'd rather rename them manually since its only a small change to the name.

+1  A: 

You could open up the designer code file and copy the bits you need directly.

You'll need to copy the declarations (at the bottom), the instantiations and any BeginInit calls (top of InitializeComponent), the properties (marked with comments), and finally the EndInit calls at the bottom. You'll also have to make sure that all the controls are added to the form/usercontrol's Controls collection, also at the bottom.

private void InitializeComponent()
{
    this.components = new System.ComponentModel.Container();
    this.button = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // button
    // 
    this.button.Location = new System.Drawing.Point(1, 5);
    this.button.Name = "Button1";        
    this.button.Size = new System.Drawing.Size(20, 50);
    // 
    // Form1
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.Controls.Add(this.button); // This is important
    this.Name = "Form1";
    this.Size = new System.Drawing.Size(569, 394);
    this.ResumeLayout(false);
}

#endregion

private System.Windows.Forms.Button button;
Ilia Jerebtsov
This is a good idea. I had started thinking along these lines - especially given that I will benefit from find and replace here. Thank you for the details on how to do it.
Ready Cent
I just finished. That was a serious task LOL. But it was better than renaming over 300 controls individually when it was only one part of each control that needed renaming.
Ready Cent
@Ready Cent, consider accepting this answer. Just a reminder.
Vulcan Eager
+1  A: 

I'm using VS 2010 RC 1, and my machine with VS 2008 is "down," so I am not sure this particular feature (in-place editing of Control names) is in VS2008: but in case it is :

  1. open the menu Views/Other Windows : select Document Outline view

  2. edit the control names directly.

It looks like the 'Document Outline' view has been around a long time: Document Outline View, but whether previous versions support in-place editing of control names: I don't know.

BillW
A: 

In VS2010 go to Tools->Options. Find Text Editor->HTML->Miscellaneous in the list of options. Un-check the checkbox next to Auto ID elements on paste in Source view.

JohnBumber