English 中文(简体)
铁道:创造和添加阿雷奥·奥图西
原标题:IronPython: Creating & Adding An Array Of Points To A GraphicsPath

奖励;

我有一点麻烦,可以正确地瞬息地看到一个系统的阿雷。 引文。 点数,然后在WinForms申请中添加“Array”点号,用于“GDI+图表”。 下面的法典按照ShapDevelop 3.2与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()

根据上述守则,我预计会看到两条永久蓝色线,每条线结束时只剩下小片。 采用上述现行计算法,计算出全球发展指数+操作时间错误红X。 我失踪或作不正确的事情是什么? 此外,还有一种更简单或更简明的办法来即时处理系统。 引文。 点值?

提前感谢你的时间和帮助......

问题回答

总之,我必须说,我不是“回答我自己的问题”,也不是独自解决这个问题,而是能够从马特·沃德和迈克尔·Foord获得外部帮助。 我最衷心地感谢马特和迈克尔两人的时间、帮助和耐心,我确实赞赏他们与他们的更正一道写回。

主要问题是我从该系统进口科罗尔语。 制图空间,以及SmoothingMode和从系统Drawing.Drawing2D名称空间的“E”数字。 虽然我的文字没有直接上列任何新增的插图或类别,但是,它们仍然必须装上,并在各自的议会中注明。 NET DLR,使其能够在我的发言稿中查阅和阅读。 (说明:再次,由于向我指出这一问题的原因;如果解释有任何错误,它们是地雷,而不是物质。)

最初对GDI+点事件的Array即时处理是正确的,但下文更正的文字中显示更为简洁的做法。 (说明:我再次感谢迈克尔指出Array即时选择。)

经更正和正在作业的主要表格:

import System.Drawing
import System.Drawing.Drawing2D 
import System.Windows.Forms

from System import Array 
from System.Drawing import Pen, Point, Color
from System.Drawing.Drawing2D import GraphicsPath, CustomLineCap, SmoothingMode, LineJoin
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+ CustomLineCaps"
        self.Paint += self.MainFormPaint
        self.ResumeLayout(False)

    def MainFormPaint(self, sender, e):
        graphics = e.Graphics
        bluePen = Pen(Color.Blue, 1)

        points = Array[Point] 
        ((Point(10, 10), Point(15, 10), Point(20, 15), 
          Point(20, 20), Point(15, 25), Point(10, 25), 
          Point(5, 20),  Point(5, 15),  Point(10, 10)))

        graphicsPath = GraphicsPath()
        graphicsPath.AddLines(points)
        graphics.SmoothingMode = SmoothingMode.AntiAlias 

        lineCap = CustomLineCap(None, graphicsPath)
        lineCap.BaseInset = 0
        lineCap.WidthScale = 1
        lineCap.StrokeJoin = LineJoin.Miter 

        bluePen.CustomStartCap = lineCap
        bluePen.CustomEndCap = lineCap

        graphics.DrawLine(bluePen, 50, 150, 200, 150)
        graphics.DrawLine(bluePen, 150, 50, 150, 200)

        lineCap.Dispose()
        graphicsPath.Dispose()
        bluePen.Dispose()




相关问题
Create a new Tuple with one element modified

(I am working interactively with a WordprocessingDocument object in IronPython using the OpenXML SDK, but this is really a general Python question that should be applicable across all implementations) ...

Why can t I import my C# type into IronPython?

I have some types in a C# library I wrote, e.g.: namespace SprocGenerator.Generators { public class DeleteGenerator : GeneratorBase { public DeleteGenerator(string databaseName, ...

IronPython ScriptRuntime equivalent to CPython PYTHONPATH

The following import works inside ipy.exe prompt but fails using IronPython ScriptRuntime inside a C# 4.0 program. import ConfigParser C# code: using System; using System.Collections.Generic; using ...

Rollback in Ironpython using System.Data.SqlClient

I am unable to rollback using the following code snippet and need help: import clr import sys clr.AddReference( System.Data ) from System.Data.SqlClient import SqlConnection, SqlParameter, ...

Nonblocking webserver on .Net for Comet applications

I am trying to implement a Comet style (e.g. chat) application using IronPython. While I don t need to scale to twitter like dimensions, it is vital that the response time is lightening fast. All ...

IronPython asp.net IntelliSense

I m trying IronPython for asp.net, I got a simple CRUD screen to work. I ve read IntelliSense doesnt work for IronPython, but is there any way to get rid of Visual Studio underlining all the lines ...

C# Running IronPython On Multiple Threads

I have a WPF app that controls audio hardware. It uses the same PythonEngine on multiple threads. This causes strange errors I see from time to time where the PythonEngines Globals dictionary has ...

热门标签