Hallo,
Ich habe das Problem das ein Objekt durch bewegen der Maus in eine PictureBox gefügt werden soll.
Doch mit dem Code:
Fachmouse.Location = MousePosition
hegt sich das Label NICHT an die Maus Position sondern deutlich von der Maus entfernt.
Wie bekomme ich es hin durch drücken des Labels (MouseDown aktiviert ein Timer, der Timer soll die Position festlegen, ein MouseUp deaktiviert den Timer) das Label wirklich an der Maus hengt?
und 2tes problem, dies Label soll auf eine PictureBox gelegt werden, die dann ihre Hintergrundfarbe ändern soll.
Doch mit
If Fachmouse.Location = PictureBox1.Location Then
PictureBox.BackColor = Color.Red
End If
Muss mann mit dem Label genau einen Punkt der PictureBox treffen, wie kann ich es machen das egal wo man das label hinlegt auf der Picture Box, das dieser Befehl trotzdem ausgefürt wird?
Hallo,
die MousePosition liefert die Position der Maus in Bildschirmkoordinaten. Dein Label bekommt die Position aber innerhalb der Form. Deswegen müsstest du da noch die Position der Form abziehen.
Für das Rüberkopieren der Farbe kannst du Drag and Drop verwenden. Zum Beispiel so:
Private Sub Label1\_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown
Label1.DoDragDrop(Color.Red, DragDropEffects.Move)
End Sub
Private Sub Label2\_MouseDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.MouseDown
Label2.DoDragDrop(Color.Blue, DragDropEffects.Move)
End Sub
Private Sub PictureBox1\_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragDrop
If e.Data.GetDataPresent(GetType(Color)) Then
Dim c As Color = e.Data.GetData(GetType(Color))
PictureBox1.BackColor = c
End If
End Sub
Private Sub PictureBox1\_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragEnter
e.Effect = e.AllowedEffect
End Sub
Private Sub Form1\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.AllowDrop = True
End Sub
Wenn du viele Labels hast, kannst du auch zum Beispiel einen EventHandler für alle anlegen und die Farbe im Tag Attribut ablegen.
Nico