Today, let's take a look at the development of user controls in. net winform. This section shows you a textbox Control with underscores and buttons. Let's take a look!
The following shows how to implement such a user control.
1. Create a user control
Add a new project-User Control
2. Drag and Drop a label, textbox, And button on the user control.
And set the properties of the control as follows:
Textbox: Set the boderstyle attribute to none.
Button: Set the image of the button to a search image.
3. Compile the control, and then you can see the control in the toolbox. Then, place the control on the interface to see the effect.
Main Code:
[Csharp]
Public partial class UCLineTextBox: UserControl
{
Public UCLineTextBox ()
{
InitializeComponent ();
}
[Category ("Custom"), Description ("show text content")]
Public override string Text
{
Get
{
Return tb. Text;
}
Set
{
Tb. Text = value;
}
}
Public delegate void ButtonClick ();
Public event ButtonClick ButtonSelectClick;
Private void tb_Enter (object sender, EventArgs e)
{
// When the mouse enters the text box, the button is visible.
Btn. Visible = true;
}
Private void tb_Leave (object sender, EventArgs e)
{
// When the mouse leaves the text box, the button disappears
Btn. Visible = false;
}
Private void UCLineTextBox_Load (object sender, EventArgs e)
{
Btn. Visible = false;
}
Private void btn_Click (object sender, EventArgs e)
{
Try
{
ButtonSelectClick. DynamicInvoke (null );
}
Catch (Exception)
{
Return;
}
}
}
Author: zx13525079024