vb.net 新建控件的事件

PublicClassForm1PrivateSubForm1_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventA... Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim mybutton As New Button
Dim mytextbox1 As New TextBox
Dim mytextbox2 As New TextBox

mytextbox1.Location = New Point(100, 50)
mybutton.Location = New Point(110, 100)
mytextbox2.Location = New Point(100, 150)

mybutton.Text = "相等"

Me.Controls.Add(mytextbox1)
Me.Controls.Add(mytextbox2)
Me.Controls.Add(mybutton)

End Sub

End Class

=============================================================
我已经新建了一个按钮(mybutton),两个文本框(mytextbox1和mytextbox2)。我想要,当单击“mybutton”时,实现“mytextbox2.text = mytextbox1.text”。我只会新建控件的代码,请问如何在新建控件中加入事件?
展开
 我来答
beeisred
2012-04-20 · TA获得超过1371个赞
知道小有建树答主
回答量:837
采纳率:0%
帮助的人:612万
展开全部
修改了一下,仅供参考
Public Class Form1
Private mybutton As New Button
Private mytextbox1 As New TextBox
Private mytextbox2 As New TextBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

mytextbox1.SetBounds(100, 50, 100, 20) 'x,y,w,h
mybutton.SetBounds(110, 100, 70, 25)
mytextbox2.SetBounds(100, 150, 100, 20)

mybutton.Text = "相等"
AddHandler mybutton.Click, AddressOf my_button '点击事件

Me.Controls.Add(mytextbox1)
Me.Controls.Add(mytextbox2)
Me.Controls.Add(mybutton)

End Sub

Private Sub my_button(ByVal sender As System.Object, ByVal e As System.EventArgs)
mytextbox2.Text = mytextbox1.Text
End Sub

End Class
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式