怎样指定一个动态增加按钮的事件(vb.net)
C#中有:控件.事件+=new事件类型(this.事件名称)在vb.net中怎样表示?都是在Sub---()Handles控件.事件名但是不能动态地加...
C#中有:
控件.事件+=new 事件类型(this.事件名称)
在vb.net中怎样表示?
都是在Sub ---()Handles 控件.事件名
但是不能动态地加 展开
控件.事件+=new 事件类型(this.事件名称)
在vb.net中怎样表示?
都是在Sub ---()Handles 控件.事件名
但是不能动态地加 展开
展开全部
''' <summary>
''' 添加大数灶多个按钮到一个容器中.
''' </summary>
''' <param name="StartPos">所有按钮开始点.</param>
''' <param name="ButtonSize">按钮的大小.</param>
''' <param name="ButtonSpace">按钮的间距</毕备param>
''' <param name="ButtonCount">按钮的总数</param>
''' <param name="AddingContainer">被添加到的容滚扮器</param>
''' <remarks></remarks>
Private Sub AddButtons(ByVal StartPos As Point, ByVal ButtonSize As Size, _
ByVal ButtonSpace As Size, ByVal ButtonCount As Integer, _
ByVal AddingContainer As Control)
Dim mBtnPos As Point = StartPos
For ItemTemp As Integer = 0 To ButtonCount - 1
Dim NewButton As Button = New Button() With
mBtnPos.Y += ButtonSpace.Height + ButtonSize.Height
If mBtnPos.Y > AddingContainer.Height Then
mBtnPos.Y = StartPos.Y
mBtnPos.X += ButtonSpace.Width + ButtonSize.Width
End If
NewButton.Text = String.Format(":", CStr(ItemTemp + 1))
AddHandler NewButton.Click, AddressOf btnzh_Click
AddingContainer.Controls.Add(NewButton)
Next
End Sub
Private Sub btnzh_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnzh.Click
Dim ItemCount As Integer = 0
Try
ItemCount = CInt(txtChoice.Text)
Catch ex As Exception
MessageBox.Show("您输入的数字无法解析为数字.")
Return
End Try
AddButtons(New Point(2, 2), New Size(60, 40), New Size(20, 30), ItemCount, Me)
End Sub
Private Sub btnzh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
''' 添加大数灶多个按钮到一个容器中.
''' </summary>
''' <param name="StartPos">所有按钮开始点.</param>
''' <param name="ButtonSize">按钮的大小.</param>
''' <param name="ButtonSpace">按钮的间距</毕备param>
''' <param name="ButtonCount">按钮的总数</param>
''' <param name="AddingContainer">被添加到的容滚扮器</param>
''' <remarks></remarks>
Private Sub AddButtons(ByVal StartPos As Point, ByVal ButtonSize As Size, _
ByVal ButtonSpace As Size, ByVal ButtonCount As Integer, _
ByVal AddingContainer As Control)
Dim mBtnPos As Point = StartPos
For ItemTemp As Integer = 0 To ButtonCount - 1
Dim NewButton As Button = New Button() With
mBtnPos.Y += ButtonSpace.Height + ButtonSize.Height
If mBtnPos.Y > AddingContainer.Height Then
mBtnPos.Y = StartPos.Y
mBtnPos.X += ButtonSpace.Width + ButtonSize.Width
End If
NewButton.Text = String.Format(":", CStr(ItemTemp + 1))
AddHandler NewButton.Click, AddressOf btnzh_Click
AddingContainer.Controls.Add(NewButton)
Next
End Sub
Private Sub btnzh_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnzh.Click
Dim ItemCount As Integer = 0
Try
ItemCount = CInt(txtChoice.Text)
Catch ex As Exception
MessageBox.Show("您输入的数字无法解析为数字.")
Return
End Try
AddButtons(New Point(2, 2), New Size(60, 40), New Size(20, 30), ItemCount, Me)
End Sub
Private Sub btnzh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
2011-01-17
展开全部
a在运行时将事件与事件处槐森理程序相关联。顷明山
AddHandler event, AddressOf eventhandler
各部分说明
event
要处理的雀中事件的名称。
eventhandler
将处理事件的过程的名称。
--------------------
Sub TestEvents()
Dim Obj As New Class1
' Associate an event handler with an event.
AddHandler Obj.Ev_Event, AddressOf EventHandler
' Call the method to raise the event.
Obj.CauseSomeEvent()
' Stop handling events.
RemoveHandler Obj.Ev_Event, AddressOf EventHandler
' This event will not be handled.
Obj.CauseSomeEvent()
End Sub
Sub EventHandler()
' Handle the event.
MsgBox("EventHandler caught event.")
End Sub
Public Class Class1
' Declare an event.
Public Event Ev_Event()
Sub CauseSomeEvent()
' Raise an event.
RaiseEvent Ev_Event()
End Sub
End Class
============================
比如:
AddHandler button1.click, AddressOf button1_click
明白了吧
AddHandler event, AddressOf eventhandler
各部分说明
event
要处理的雀中事件的名称。
eventhandler
将处理事件的过程的名称。
--------------------
Sub TestEvents()
Dim Obj As New Class1
' Associate an event handler with an event.
AddHandler Obj.Ev_Event, AddressOf EventHandler
' Call the method to raise the event.
Obj.CauseSomeEvent()
' Stop handling events.
RemoveHandler Obj.Ev_Event, AddressOf EventHandler
' This event will not be handled.
Obj.CauseSomeEvent()
End Sub
Sub EventHandler()
' Handle the event.
MsgBox("EventHandler caught event.")
End Sub
Public Class Class1
' Declare an event.
Public Event Ev_Event()
Sub CauseSomeEvent()
' Raise an event.
RaiseEvent Ev_Event()
End Sub
End Class
============================
比如:
AddHandler button1.click, AddressOf button1_click
明白了吧
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询