Just for fun. This IronPython script shows how you can create a form with movable button.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | import clr
clr.AddReference("System.Drawing")
clr.AddReference("System.Windows.Forms")
from System.Drawing import Point, Size
from System.Windows.Forms import (
Application, Button, Form, FormStartPosition, MouseButtons
)
class frmMain(Form):
def __init__(self):
self._blnMoving = False
self.InitializeComponent()
def InitializeComponent(self):
self._btnMouse = Button()
#
#btnMouse
#
self._btnMouse.Location = Point(self.Width / 2, self.Height / 2)
self._btnMouse.Size = Size(110, 27)
self._btnMouse.Text = "Click me and move"
self._btnMouse.MouseDown += self.btnMouse_MouseDown
self._btnMouse.MouseMove += self.btnMouse_MouseMove
self._btnMouse.MouseUp += self.btnMouse_MouseUp
#
#frmMain
#
self.ClientSize = Size(570, 370)
self.Controls.Add(self._btnMouse)
self.StartPosition = FormStartPosition.CenterScreen
self.Text = "MovableButton"
def btnMouse_MouseDown(self, sender, e):
if e.Button == MouseButtons.Left:
self._blnMoving = True
self._btnLocate = e.Location
def btnMouse_MouseMove(self, sender, e):
if self._blnMoving:
btn = sender
btn.Location = Point(btn.Left - self._btnLocate.X + e.X,
btn.Top - self._btnLocate.Y + e.Y)
def btnMouse_MouseUp(self, sender, e):
if e.Button == MouseButtons.Left:
self._blnMoving = False
if __name__ == "__main__":
Application.EnableVisualStyles()
Application.Run(frmMain())
|
Tags: button, ironpython