1

#Develop で IronPython を使い始めました。IronPython と Windows Forms との統合が気に入っています。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 に答える