这有效。它在面板上绘制一个简单的矩形:
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)
一切都是对象 - 但我如何引用这个矩形?
我想在稍后在代码中创建椭圆时使用这个矩形作为参数之一(即在矩形中绘制椭圆) - 为什么我不能执行以下操作?
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)
最佳答案
声明你的矩形并使用它的值:
Dim r As New Rectangle(10, 50, 50, 50)
g.DrawRectangle(fPen, r.Location.X, r.Location.Y, r.Width, r.Height)
g.DrawEllipse(fPen, r)
关于vb.net - 捕获矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15289788/