问候;
我在正确实例化 System.Drawing.Point 实例数组,然后在 WinForms 应用程序中使用 IronPython 将点数组添加到 GDI+ GraphicsPath 实例时遇到了一些麻烦。以下代码在 SharpDevelop 3.2 和 IronPython 2.6 下正确编译或构建:
import System.Drawing
import System.Drawing.Drawing2D
import System.Windows.Forms
from System import Array
from System.Drawing import Pen, Point
from System.Drawing.Drawing2D import GraphicsPath, CustomLineCap
from System.Windows.Forms import *
class MainForm(Form):
def __init__(self):
self.InitializeComponent()
def InitializeComponent(self):
self.SuspendLayout()
#
# MainForm
#
self.ClientSize = System.Drawing.Size(284, 264)
self.Name = "MainForm"
self.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
self.Text = "GDI Lines"
self.Paint += self.MainFormPaint
self.ResumeLayout(False)
def MainFormPaint(self, sender, e):
graphicContext = e.Graphics
bluePen = Pen(Color.Blue, 1)
points = Array.CreateInstance(Point, 9)
points[0] = Point(10, 10)
points[1] = Point(15, 10)
points[2] = Point(20, 15)
points[3] = Point(20, 20)
points[4] = Point(15, 25)
points[5] = Point(10, 25)
points[6] = Point(5, 20)
points[7] = Point(5, 15)
points[8] = Point(10, 10)
graphicsPath = GraphicsPath()
graphicsPath.AddLines(points)
graphicContext.SmoothingMode = SmoothingMode.AntiAlias
lineCap = CustomLineCap(nil, graphicsPath)
lineCap.BaseInset = 0
lineCap.WidthScale = 1
lineCap.StrokeJoin = LineJoin.Miter
bluePen.CustomStartCap = lineCap
bluePen.CustomEndCap = lineCap
graphicContext.DrawLine(bluePen, 50, 150, 200, 150)
graphicContext.DrawLine(bluePen, 150, 50, 150, 200)
lineCap.Dispose()
graphicsPath.Dispose()
bluePen.Dispose()
根据上面的代码,我希望看到两条垂直的蓝线,每条线的末端都有一个小椭圆。使用上面的当前 scipting 代码,绘制了 GDI+ 运行时错误红色 X。我错过了什么或做错了什么?此外,是否有更简单或更简洁的方法来实例化 System.Drawing.Point 值的数组?
提前感谢您的时间和帮助...