Ik zal een aanzetje geven (de rest kan je hier wel uit afleiden denk ik al vergt een cirkel wel iets andere aanpak):
Maak een form zet daarop 5 shapes (rechthoeken) genaamd Shape1,Shape2,...,Shape5, voeg ook een Image toe (genaamd Image1). Zet van Shape2 t/m Shape5 de fillstyle op Solid. Plaats Shape1 gedeeltelijk over Image1 heen en run het programma.
Click en sleep nu het plaatje (op het zichtbare deel) het plaatje zal nu onder de mask heen- en weerschuiven.
Visual Basic:
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
| Option Explicit
Option Base 0
'Code by stern@gangsterdam.nl
Private mStartX As Single
Private mStartY As Single
Private Sub MakeCutOut(inImage As Image, inShape As Shape)
Dim MaskColor As Long
Dim ShapeLeft As Shape
Dim ShapeRight As Shape
Dim ShapeTop As Shape
Dim ShapeBottom As Shape
MaskColor = vbYellow
'Make the background same as maskcolor
Me.BackColor = MaskColor
'Make the shape border same as maskcolor
inShape.BorderColor = MaskColor
If inImage.Left < inShape.Left Then
'We need to fill up the left side
Set ShapeLeft = Shape2
ShapeLeft.BorderColor = MaskColor
ShapeLeft.FillColor = MaskColor
ShapeLeft.Left = inImage.Left
ShapeLeft.Top = inImage.Top
ShapeLeft.Height = inImage.Height
ShapeLeft.Width = inShape.Left - inImage.Left
ShapeLeft.Visible = True
End If
If inShape.Top > inImage.Top Then
'We need to fill up the top side
Set ShapeTop = Shape3
ShapeTop.BorderColor = MaskColor
ShapeTop.FillColor = MaskColor
ShapeTop.Left = inImage.Left
ShapeTop.Top = inImage.Top
ShapeTop.Width = inImage.Width
ShapeTop.Height = inShape.Top - inImage.Top
ShapeTop.Visible = True
End If
'inImage.Right > inShape.Right
If inImage.Left + inImage.Width > inShape.Left + inShape.Width Then
'We need to fill up the right side
Set ShapeRight = Shape4
ShapeRight.BorderColor = MaskColor
ShapeRight.FillColor = MaskColor
ShapeRight.Left = inShape.Left + inShape.Width
ShapeRight.Top = inImage.Top
ShapeRight.Width = inImage.Left + inImage.Width - (inShape.Left + inShape.Width)
ShapeRight.Height = inImage.Height
ShapeRight.Visible = True
End If
If inImage.Top + inImage.Height > inShape.Top + inShape.Height Then
'We need to fill up the bottom side
Set ShapeBottom = Shape5
ShapeBottom.BorderColor = MaskColor
ShapeBottom.FillColor = MaskColor
ShapeBottom.Left = inImage.Left
ShapeBottom.Top = inShape.Top + inShape.Height
ShapeBottom.Width = inImage.Width
ShapeBottom.Height = inImage.Top + inImage.Height - (inShape.Top + inShape.Height)
ShapeBottom.Visible = True
End If
End Sub
Private Sub Form_Load()
MakeCutOut Image1, Shape1
End Sub
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Image1.Visible = False
If Button = 1 Then
'Left mouseclick
mStartX = X
mStartY = Y
End If
End Sub
Private Sub Image1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Image1.Left = Image1.Left - (mStartX - X)
Image1.Top = Image1.Top - (mStartY - Y)
End If
MakeCutOut Image1, Shape1
Image1.Visible = True
End Sub |