-
Notifications
You must be signed in to change notification settings - Fork 0
/
029_DragButton.py
44 lines (29 loc) · 1.01 KB
/
029_DragButton.py
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
#!/usr/bin/ipy
import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Windows.Forms import Application, Form, Button
from System.Drawing import Size, Point
class IForm(Form):
def __init__(self):
self.Text = 'Drag & Drop'
button = Button()
button.Parent = self
button.Text = 'Button'
button.MouseDown += self.OnMousDown
button.MouseUp += self.OnMousUp
button.MouseMove += self.OnMousMove
button.Location = Point(20, 20)
self.isDragging = False
self.CenterToScreen()
def OnMousDown(self, sender, event):
self.isDragging = True
self.oldX = event.X
self.oldY = event.Y
def OnMousMove(self, sender, event):
if self.isDragging:
sender.Top = sender.Top + (event.Y - self.oldY)
sender.Left = sender.Left + (event.X - self.oldX)
def OnMousUp(self, sender, event):
self.isDragging = False
Application.Run(IForm())