Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
For i = 0 To 3
Dim Datagridd As New DataGrid()
Datagridd.Left = i * 80
Me.Controls.Add(Datagridd)
AddHandler Datagridd.MouseUp, AddressOf DataGridd_MouseUp
'初始化3个datagrid....
Next i
End Sub
WithEvents obj As New DataGrid()
Private Sub DataGridd_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles obj.MouseUp
If obj.CurrentRowIndex <> -1 Then
obj.Select(obj.CurrentRowIndex)
End If
End Sub
Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'动态产生datarid1
dim datagrd1 as new datagrid
'增加事件处理响应
AddHandler datagridd.MouseUp, AddressOf DataGridd_MouseUp
end sub
Private Sub DataGridd_MouseUp(ByVal sender As Object, ByVal e As _& System.Windows.Forms.MouseEventArgs)
'怎么引用刚才定义的datagridd 呢
datagridd.select(DataGridd.currentindex)'这不行,可是我想实现点击后实现选中行
----------------------------------------
end sub
看看我做的吧:
Dim lb As New MyButton()
AddHandler lb.Click, AddressOf obj_Click
WithEvents obj As New Control()
Private Sub obj_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles obj.Click
'处理代码
End Sub
这样就可以了。
' Binds the event handler DrawOnTab to the DrawItem event
' through the DrawItemEventHandler delegate.
AddHandler tabControl1.DrawItem, AddressOf DrawOnTab
End Sub
' Declares the event handler DrawOnTab which is a method that
' draws a string and Rectangle on the tabPage1 tab.
Private Sub DrawOnTab(ByVal sender As Object, ByVal e As DrawItemEventArgs)
Dim g As Graphics = e.Graphics
Dim p As New Pen(Color.Blue)
Dim font As New Font("Arial", 10.0F)
Dim brush As New SolidBrush(Color.Red)
g.DrawRectangle(p, tabArea)
g.DrawString("tabPage1", font, brush, tabTextArea)
End Sub
Shared Sub Main()
Application.Run(New Form1())
End Sub
End Class