111,093
社区成员




Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim test As New TextButtonControl
AddHandler test.ButtonClick, AddressOf TestControlClick
AddHandler test.TextBoxTextChanged, AddressOf TestControlTextChanged
Me.Controls.Add(test)
End Sub
Private Sub TestControlClick(ByVal sender As Object, ByVal e As EventArgs)
MsgBox("ButtonClick")
End Sub
Private Sub TestControlTextChanged(ByVal sender As Object, ByVal e As EventArgs)
MsgBox("TextChanged")
End Sub
End Class
Public Class TextButtonControl
Inherits System.Windows.Forms.Panel
Private WithEvents txtBox As TextBox
Private WithEvents btn As Button
Public Event ButtonClick(ByVal sender As Object, ByVal e As EventArgs)
Public Event TextBoxTextChanged(ByVal sender As Object, ByVal e As EventArgs)
Public Sub New()
Me.BorderStyle = Windows.Forms.BorderStyle.Fixed3D
Me.MinimumSize = New Size(50, 22)
txtBox = New TextBox With {.BorderStyle = Windows.Forms.BorderStyle.None}
btn = New Button With {.Text = "…"}
Me.Controls.Add(txtBox)
Me.Controls.Add(btn)
End Sub
Private Sub TextButtonControl_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
Me.Height = 21
btn.SetBounds(Me.Width - 24, 1, 20, 18)
txtBox.SetBounds(2, 2, Me.Width - 28, 21)
End Sub
Private Sub txtBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtBox.TextChanged
RaiseEvent TextBoxTextChanged(sender, e)
End Sub
Private Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn.Click
RaiseEvent ButtonClick(sender, e)
End Sub
End Class
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(104, 142);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(309, 231);
this.textBox1.TabIndex = 3;
//
// button2
//
this.button2.Location = new System.Drawing.Point(299, 195);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 4;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
TextBox TB = new TextBox();
TB.Parent = this;
Button B = new Button();
B.Parent = TB;
B.Width = 40;
B.Dock = DockStyle.Right;
B.BackColor = SystemColors.Control;