1

我已经开始在#Develop 中使用 IronPython,并且我喜欢与 IronPython 和 Windows 窗体的集成,它可以让您创建类似于 Visual Basic 或 C# 的 GUI

我的问题很简单,单击时如何在 PictureBox 中画一条线?我找到了有关绘制线条的代码,但我知道如何将其调整为 PictureBox。

这是我找到的代码: http ://www.zetcode.com/tutorials/ironpythontutorial/painting/

那么,我应该在“def PictureBox1Click(self,sender,e):”中输入什么?

任何帮助或指导将不胜感激。

4

1 回答 1

1

这是一个简单的示例,当单击图片框时,它会在图片框上画一条线。

import System.Drawing
import System.Windows.Forms

from System.Drawing import *
from System.Windows.Forms import *

class MainForm(Form):
  def __init__(self):
    self.InitializeComponent()
    self.pen = System.Drawing.Pen(System.Drawing.Color.Black);

  def InitializeComponent(self):
    self._pictureBox1 = System.Windows.Forms.PictureBox()
    self._pictureBox1.BeginInit()
    self.SuspendLayout()
    # 
    # pictureBox1
    # 
    self._pictureBox1.Location = System.Drawing.Point(13, 13)
    self._pictureBox1.Name = "pictureBox1"
    self._pictureBox1.Size = System.Drawing.Size(259, 237)
    self._pictureBox1.TabIndex = 0
    self._pictureBox1.TabStop = False
    self._pictureBox1.Click += self.PictureBox1Click
    # 
    # MainForm
    # 
    self.ClientSize = System.Drawing.Size(284, 262)
    self.Controls.Add(self._pictureBox1)
    self.Name = "MainForm"
    self.Text = "PyWinForm"
    self._pictureBox1.EndInit()
    self.ResumeLayout(False)


  def PictureBox1Click(self, sender, e):
    g = self._pictureBox1.CreateGraphics()
    g.DrawLine(self.pen, 10, 10, 400, 200)
于 2012-11-15T18:03:15.083 回答