Windows forms designer renaming copy/pasted controls
I saw a s开发者_如何学Goimilar question asked and answered for ASP.net here 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.
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 :
open the menu Views/Other Windows : select Document Outline view
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.
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;
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.
精彩评论