Click here to Skip to main content
15,887,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have made a simple user control by inheriting the button base control and named it myButton and have set the button text to 'ABC'.

When I drag the myButton from the toolbox onto a form, the button text becomes 'myButton1'.

Is there a way to keep the original text and MAYBE also control the name?

JP
Posted

Yes, you can control it using ToolboxData Attribute[^]

Sample:
[ToolboxData("<{0}:MyLabel Text='MyLabel' BorderColor='Yellow' runat=\'server\'>")]
 
Share this answer
 
Comments
Albin Abel 15-Feb-11 12:33pm    
my 5
JPScerri 16-Feb-11 2:10am    
Unfortunately this is for web forms. I need a solution for Win Forms.
JP
Albin Abel 16-Feb-11 3:14am    
look at my answer for the winform. When you drag and place it will show the text you assigned by default
Alternatively If it is a Windows Form application then override the OnPaint event as below

C#
protected override void OnPaint(System.Windows.Forms.PaintEventArgs pevent)
{
    this.Text = "ABC";
    base.OnPaint(pevent);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900