質問

I've started working with IronPython in #Develop, and i love the integration with IronPython and Windows Forms, it lets you create the GUI like is were Visual Basic or C#

The question i have is simple, how to draw a line into a PictureBox when it's clicked? I've found this code about drawing lines, but i know how to adapt it to a PictureBox.

This is the code i've found: http://www.zetcode.com/tutorials/ironpythontutorial/painting/

So, what should i put in "def PictureBox1Click(self, sender, e):"?

Any help or guide would be gratly appreciated.

役に立ちましたか?

解決

Here is a simple example that draws a line on a picture box when it is clicked.

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)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top