积极答复者
如何向Paint事件中传递参数

问题
-
你好,
我知道在动态添加的Picturebox中Drawstring,drawrectangle时要在paint事件中来进行。
代码简述:
dim Pnl as panel =new panel
with pnl
....
end with
me.controls.add(Pnl)
for i=1 to 5 step 1
Dim Pb As PictureBox = New PictureBox
With Pb
....dock=dockstyle.top
End With
AddHandler Pb.Paint, AddressOf Pb_Paint
Pnl.Controls.Add(Pb)next
end sub
Private Sub Pb_Paint(Sender As Object, e As PaintEventArgs)
dim bursh,pen
...
e.Graphics.DrawString(VAR,myfont, mybrush, 30, 30)
...
e.Graphics.DrawRectangle(mypen, rect)
end sub
在这个过程里字符串和方块的尺寸以及填充色是不一样的,如果传递rect的定义和方块的定义呢?
答案
-
你好,
在我看来,给事件传递参数,你可以按照.NET事件传递参数的标准,为了传递你自定义的参数,你需要创建事件参数类,这个类需要继承EventArgs类。你可以参考下面的代码:
Public Class RefreshGridEventArgs Inherits EventArgs Public Property OrderId As Integer Public Sub New(wOrderId As Integer) MyBase.New() Me.OrderId = wOrderId End Sub End Class
定义完事件参数类后,需要重新定义事件
Public Event RefreshGrid(sender As Object, e As RefreshGridEventArgs)
下一步定义怎样触发事件:
' Replace 1 with the actual order idRaiseEvent RefreshGrid(Me, New RefreshGridEventArgs(1))
最后,在事件的处理方法中,使用 e.OrderId获你已经定义好的参数We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 Yu Du 2015年6月26日 2:21
全部回复
-
你好,
在我看来,给事件传递参数,你可以按照.NET事件传递参数的标准,为了传递你自定义的参数,你需要创建事件参数类,这个类需要继承EventArgs类。你可以参考下面的代码:
Public Class RefreshGridEventArgs Inherits EventArgs Public Property OrderId As Integer Public Sub New(wOrderId As Integer) MyBase.New() Me.OrderId = wOrderId End Sub End Class
定义完事件参数类后,需要重新定义事件
Public Event RefreshGrid(sender As Object, e As RefreshGridEventArgs)
下一步定义怎样触发事件:
' Replace 1 with the actual order idRaiseEvent RefreshGrid(Me, New RefreshGridEventArgs(1))
最后,在事件的处理方法中,使用 e.OrderId获你已经定义好的参数We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 Yu Du 2015年6月26日 2:21