2012-11-11 2 views
1

J'ai commencé à travailler avec IronPython dans #Develop, et j'aime l'intégration avec IronPython et Windows Forms, il vous permet de créer l'interface graphique comme Visual Basic est étaient ou C#Comment dessiner des lignes dans IronPython avec Winforms?

La question que j'est simple, comment dessiner une ligne dans un PictureBox quand il est cliqué? J'ai trouvé ce code sur les lignes de dessin, mais je sais comment l'adapter à un PictureBox.

Voici le code que j'ai trouvé: http://www.zetcode.com/tutorials/ironpythontutorial/painting/

Alors, que dois-je mettre en "def PictureBox1Click (auto, expéditeur, e):"?

Toute aide ou guide serait grandement apprécié.

Répondre

1

Voici un exemple simple qui trace une ligne sur une zone d'image lorsque vous cliquez dessus.

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) 
Questions connexes