【发布时间】:2014-10-13 15:04:40
【问题描述】:
可以知道Graphics 对象的ownercontrol 吗?
在此方法中,我将控件的图形对象连同控件的宽度和高度一起传递给自定义方法:
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) _
Handles PictureBox1.Paint
Me.MyMethod(g:=e.Graphics, Width:=sender.width, Height:=sender.height)
End Sub
但我想避免将宽度和高度参数传递给我的方法(或传递控件),而是 MyMethod 应该仅通过图形对象找到控件宽度/高度,以防万一.
类似这样的伪代码:
private sub mymethod(byval g as graphics)
dim _width as integer = g.GetControlWidth
dim _height as integer = g.GetontrolHeight
end sub
【问题讨论】:
-
你的问题的前提有缺陷:仅仅因为你在控件的绘制事件中获取了图形对象,并不意味着图形与它相关。
System.Drawing.Graphics与控件没有直接关系。MyMethod(g As Graphics, ctl As Control)与您将得到的一样接近,并且仍然会在其他与绘制相关的事件(e.DrawBackGround、e.DrawFocusRect、e.PaintParentBackground 等)中丢失其他e事件参数。 -
谢谢 plutonix 然后这个问题解决了,如果你愿意的话,发布一个答案
标签: .net vb.net winforms gdi+ gdi