Aktion machen wenn picture box ein panel berührt
- VB.NET
Sie verwenden einen veralteten Browser (%browser%) mit Sicherheitsschwachstellen und können nicht alle Funktionen dieser Webseite nutzen.
Hier erfahren Sie, wie einfach Sie Ihren Browser aktualisieren können.
Hier erfahren Sie, wie einfach Sie Ihren Browser aktualisieren können.
Es gibt 31 Antworten in diesem Thema. Der letzte Beitrag () ist von ChRoNiK.
-
-
-
-
back-side.net/codingrects.html
(Für dich: den letzten Abschnitt lesen) -
-
Speicher die Koordinaten in einem Rectangle und prüfe die Eckpunkte des anderem mit .Contains(). Da musst du dann in die Klammern die Point-Variable eintragen.
-
-
-
-
-
-
-
KouKi hat schon die Frage schon beantwortet!!!
Für dich extra C&P:
<code>
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim rec1 As New Rectangle(PictureBox1.Location.X, PictureBox1.Location.Y, _
PictureBox1.Width, PictureBox1.Height)
Dim rec2 As New Rectangle(Panel1.Location.X, _
Panel1.Location.Y, Panel1.Width, Panel1.Height)
If rec1.Contains(rec2.X, rec2.Y) OrElse rec1.Contains(rec2.X + rec2.Width, rec2.Y + rec2.Height) Then
MessageBox.Show("Kollidiert")
End If
End Sub
End Class
<code>Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „agon“ ()
-
-
-
Okay, na dann
Noch mal 'n bisschen C&P für den Threadersteller: (Achtung! 2 Panels statt 1 PictureBox + 1 Panel!)
VB.NET-Quellcode
- Private Sub Panel2_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel2.Move, Panel1.Move
- Dim rec1 As New Rectangle(Panel1.Location.X, Panel1.Location.Y, Panel1.Width, Panel1.Height)
- Dim rec2 As New Rectangle(Panel2.Location.X, Panel2.Location.Y, Panel2.Width, Panel2.Height)
- If rec1.IntersectsWith(rec2) Then MessageBox.Show("Kollidiert.")
- End Sub
Aber: Das war das letzte mal, dass ich C&P gebe! -
-
-
einfach den code kopiert
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim rec1 As New Rectangle(PictureBox1.Location.X, PictureBox1.Location.Y, PictureBox1.Width, PictureBox1.Height)
Dim rec2 As New Rectangle(Panel2.Location.X, Panel2.Location.Y, Panel2.Width, Panel2.Height)
If rec1.Contains(rec2.X, rec2.Y) OrElse rec1.Contains(rec2.X + rec2.Width, rec2.Y + rec2.Height) Then
MessageBox.Show("Kollidiert")
End If
End Sub
oder soll ich den ganzen code zeigen? -
Wie ich ein paar Posts vorher schon sagte, KEINEN Timer benutzen, sondern mit den Move-Ereignissen beider Steuerelemente arbeiten. Ist wesentlich schneller, weil es SOFORT, wenn das Objekt bewegt wird, ausgelöst wird. Anscheinend hast du schlecht kopiert, denn mein Code war direkt im Move-Ereignis, hättest nur Panel2 durch PictureBox1 ersetzen müssen (Hab ich jetzt für dich gemacht):
VB.NET-Quellcode
- Private Sub PictureBox1_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.Move, Panel1.Move
- Dim rec1 As New Rectangle(Panel1.Location.X, Panel1.Location.Y, Panel1.Width, Panel1.Height)
- Dim rec2 As New Rectangle(PictureBox1.Location.X, PictureBox1.Location.Y, PictureBox1.Width, PictureBox1.Height)
- If rec1.IntersectsWith(rec2) Then MessageBox.Show("Kollidiert.")
- End Sub
Von wegen Kopiert
-
Ähnliche Themen
-
korbi999 - - Sonstige Problemstellungen