gpt4 book ai didi

python - 如何使用 Winforms 在 IronPython 中画线?

转载 作者:太空宇宙 更新时间:2023-11-03 19:09:54 26 4
gpt4 key购买 nike

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

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

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

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

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

最佳答案

这是一个简单的示例,当单击图片框时在该框上绘制一条线。

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)

关于python - 如何使用 Winforms 在 IronPython 中画线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13334024/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com