Option 1:
You can make your TextBox
public. to do so, go to designer of your user control, then select Modifier
property and the set the value to public.
Now you can access it outside of your control. For example if you have an instance of your user control with name of userControl1
and name of your text box is txtb
:
userControl1.txtb.BackColor = Color.Red;
Option 2:
As another option you can create a public property and in that property get or set your textbox color.
public Color TextBoxBackColor
{
get
{
return txtb.BackColor;
}
set
{
txtb.BackColor = value;
}
}
Now you can access this property outside of your control. For example if you have an instance of your user control with name of userControl1
:
userControl1.TextBoxBackColor = Color.Red;
Since you are building a user control, changing the color of the textbox can be treated as a feature of the control and can be provided to clients by adding a property.
[Browsable(true)] // allows you to change it in the designer
public Color TextBoxBackColor
{
get { return txtb.BackColor; }
set { txtb.BackColor = value; }
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.