マウスでクリックした位置に円を描画する
マウスでクリックした位置に円を描画するプログラムは以下の通り。クリックした座標をすべて記録しておく。
import clr clr.AddReference("System.Windows.Forms") clr.AddReference("System.Drawing") from System.Windows.Forms import Application, Form from System.Drawing import Size, Brushes from System.Drawing.Drawing2D import DashStyle class IForm(Form): def __init__(self): self.Text = 'Circles' self.Size = Size(280, 270) self.coords = list() self.Click += self.OnClick self.Paint += self.OnPaint self.CenterToScreen() def OnClick(self, event): xy = [event.X, event.Y] self.coords.append(xy) self.Invalidate() def OnPaint(self, event): g = event.Graphics for i in range(len(self.coords)): xs = self.coords[i][0] ys = self.coords[i][1] g.FillEllipse(Brushes.Green, xs, ys, 10, 10) g.Dispose() Application.Run(IForm())