Hallo Boyle,
hier ein Beispiel zum Verschieben von Linien mit der Maus:
'Benötigt werden: 1 x Label, 2 x PictureBox, 1 x Line-Control
Option Explicit
Private LIx&, XPos%, YPos%, LN%(), LFarb&()
Private Sub Form_Load()
Dim i%, N%, Farbe&, P1%, P2%, P3%, P4%
Me.ScaleMode = 3
Me.WindowState = 2
Line1.Visible = False
Set Line1.Container = Picture1
With Picture1
.BackColor = 0
.Move 10, 10, 400, 304
.ScaleMode = 3
.AutoRedraw = True
.Cls
Label1.Move .Left + .Width, .Top
Picture2.BorderStyle = .BorderStyle
Picture2.Move 0, 0, .Width, .Height
With Picture2
.Visible = False
.BackColor = vbWhite
.Cls
.ScaleMode = 3
.AutoRedraw = True
.DrawWidth = 5 'Anfassbereich
End With
N = 0
For i = 30 To .ScaleWidth - 30 Step 30
P1 = i: P2 = 0: P3 = i: P4 = .ScaleHeight - 1
Farbe = vbRed 'beliebig
GoSub Setze
Next i
For i = 30 To .ScaleHeight - 30 Step 30
P1 = 0: P2 = i: P3 = .ScaleWidth - 1: P4 = i
Farbe = vbBlue 'beliebig
GoSub Setze
Next i
End With
Exit Sub
Setze:
ReDim Preserve LN(3, N), LFarb(N)
LN(0, N) = P1
LN(1, N) = P2
LN(2, N) = P3
LN(3, N) = P4
LFarb(N) = Farbe
Picture1.Line (P1, P2)-(P3, P4), Farbe
Picture2.Line (P1, P2)-(P3, P4), N
N = N + 1
Return
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As _
Single, Y As Single)
Dim i%
XPos = X
YPos = Y
LIx = Picture2.Point(X, Y)
If LIx = vbWhite Then
LIx = -1
Else
Picture1.Cls
For i = 0 To UBound(LN, 2)
If i <> LIx Then
Picture1.Line (LN(0, i), LN(1, i))-(LN(2, i), LN(3, i)), LFarb(i)
End If
Next i
With Line1
.X1 = LN(0, LIx)
.Y1 = LN(1, LIx)
.X2 = LN(2, LIx)
.Y2 = LN(3, LIx)
.BorderColor = LFarb(LIx)
.ZOrder
.Visible = True
End With
End If
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As _
Single, Y As Single)
If Button = vbLeftButton And LIx <> -1 Then
With Line1
If .X1 = .X2 Then
.X1 = LN(0, LIx) - XPos + X
.X2 = .X1
Else
.Y1 = LN(1, LIx) - YPos + Y
.Y2 = .Y1
End If
End With
ElseIf Button = 0 Then
LIx = Picture2.Point(X, Y)
If LIx = vbWhite Then
Label1.Caption = "leer"
LIx = -1
Else
Label1.Caption = "Linie " & LIx
End If
End If
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, _
Y As Single)
Dim i%
If LIx <> -1 Then
With Line1
.Visible = False
LN(0, LIx) = .X1
LN(1, LIx) = .Y1
LN(2, LIx) = .X2
LN(3, LIx) = .Y2
Picture1.Line (.X1, .Y1)-(.X2, .Y2), .BorderColor
End With
Picture2.Cls
For i = 0 To UBound(LN, 2)
Picture2.Line (LN(0, i), LN(1, i))-(LN(2, i), LN(3, i)), i
Next i
End If
End Sub Gruß
Zardoz |