ご挨拶;
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()
上記のコードに基づいて、2 つの垂直な青い線が描画され、各線の最後に小さな楕円が表示されることを期待していました。上記の現在の scipting コードを使用すると、GDI+ ランタイム エラーの赤い X が描画されます。何が欠けているか、間違っていますか? また、System.Drawing.Point 値の配列をインスタンス化する、より簡単で簡潔な方法はありますか?
お時間を割いてご協力いただき、ありがとうございました...