这有效。它利用一个简单的矩形面板上:捕获矩形
Dim g As Graphics
Dim fPen As Pen
g = aPanel.CreateGraphics()
fPen = New Pen(Color.Blue)
Dim PointX As Point = New Point(10, 20)
Dim PointY As Point = New Point(50, 50)
g.DrawRectangle(fPen, PointY.X, PointY.Y, 50, 50)
一切都是对象 - 但我如何引用这ractangle?
我希望在代码中稍后创建椭圆时(即在矩形中绘制椭圆)时,使用此矩形作为参数之一 - 为什么我不能执行以下操作?
Dim g As Graphics
Dim fPen As Pen
g = aPanel.CreateGraphics()
fPen = New Pen(Color.Blue)
Dim PointX As Point = New Point(10, 20)
Dim PointY As Point = New Point(50, 50)
Dim r As Rectangle
r = New Rectangle(g.DrawRectangle(fPen, PointY.X, PointY.Y, 50, 50)) '<<<errors here
g.DrawEllipse(fPen, r)
'DrawRectangle'不返回任何东西(它是一个'Sub'')。 – Styxxy 2013-03-08 08:42:08
使用CreateGraphics绘制的任何东西都会消失,如果窗口最小化或者其他窗口在其前面通过。您应该在面板的Paint事件中进行绘画。 – 2013-03-08 15:23:32