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”。我只会新建控件的代码,请问如何在新建控件中加入事件? 展开
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”。我只会新建控件的代码,请问如何在新建控件中加入事件? 展开
展开全部
修改了一下,仅供参考
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询