Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 13:16

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Picturebox Bewegungs Problemme VB 2010

Discussion on Picturebox Bewegungs Problemme VB 2010 within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Jan 2013
Posts: 131
Received Thanks: 11
Smile Picturebox Bewegungs Problemme VB 2010

Hey ho

Ich wollte mal aus Spaß ein Programm schreiben wo wen ich auf die Space
Taste drücke eine Picturebox auf die Position einer Picturebox Spawnt
und dann nach Links von alleine gleiten soll :? nun ist das aber so
wen ich die Space Taste drücke das die gespawnte Picturebox zwar auf die Position spwant aber sich nicht mehr bewegt woran kann das Liegen ? :?

Das hier ist soweit der code der dies bewirken sollte;

Code:
Public Class Form1
    Dim ResourceFilePath As String
    Public WithEvents PictureBox1 As PictureBox
    Public WithEvents PictureBox2 As PictureBox
    Public WithEvents Timer1 As Timer
   Public WithEvents Timer2 As Timer
   Public WithEvents Timer3 As Timer
   Public WithEvents Timer4 As Timer
   Public WithEvents Timer5 As Timer
    Public WithEvents Label1 As Label
Public Sub New()
Me.StartPosition = FormStartPosition.CenterScreen
        Me.Text = "Game"
        Me.MaximumSize = New System.Drawing.Size(800, 600)
        Me.MinimumSize = New System.Drawing.Size(800, 600)
        Me.Size = New System.Drawing.Size(800, 600)
        Me.TopMost = True
        Me.BackgroundImage = My.Resources.Titel_Bild
 Label1 = New Label()
        Label1.Size = New Size(200, 80)
        Label1.Location = New Point(340, 470)
        Me.Controls.Add(Label1)
        Label1.ForeColor = Color.OrangeRed
        Label1.BackColor = Color.Transparent
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 20.0!,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
        Label1.Text = "Starten"
        timer1 = New Timer()
        Timer1.Interval = "5"
        timer2 = New Timer()
        Timer2.Interval = "5"
        timer3 = New Timer()
        Timer3.Interval = "5"
        timer4 = New Timer()
        Timer4.Interval = "5"
        timer5 = New Timer()
        Timer5.Interval = "5"
    End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
        Me.BackgroundImage.Dispose()
        Me.BackgroundImage = Nothing
        Me.BackColor = Color.Green
        Me.Controls.Remove(Label1)
        PictureBox1 = New PictureBox()
        PictureBox1.Size = New Size(40, 66)
        PictureBox1.Location = New Point(355, 249)
        Me.Controls.Add(PictureBox1)
        PictureBox1.BackgroundImage = My.Resources.Char3
        PictureBox1.BackgroundImageLayout = ImageLayout.Stretch
    End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        'Nach Oben Gehen
        PictureBox1.Size = New Size(40, 66)
        PictureBox1.BackgroundImage = My.Resources.Char1
        PictureBox1.BackgroundImageLayout = ImageLayout.Stretch
        PictureBox1.Top = PictureBox1.Top - 1
    End Sub
    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        'Nach Unten Gehen
        PictureBox1.Size = New Size(40, 66)
        PictureBox1.BackgroundImage = My.Resources._Char
        PictureBox1.BackgroundImageLayout = ImageLayout.Stretch
        PictureBox1.Top = PictureBox1.Top + 1
    End Sub
    Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        'Nach Rechts Gehen
        PictureBox1.Size = New Size(40, 66)
        PictureBox1.BackgroundImage = My.Resources.Char5
        PictureBox1.BackgroundImageLayout = ImageLayout.Stretch
        PictureBox1.Left = PictureBox1.Left + 1
    End Sub
    Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
        'Nach Links Gehen
        PictureBox1.Size = New Size(40, 66)
        PictureBox1.BackgroundImage = My.Resources.Char4
        PictureBox1.BackgroundImageLayout = ImageLayout.Stretch
        PictureBox1.Left = PictureBox1.Left - 1
    End Sub
    Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer5.Tick
        'Blut Attacke

        PictureBox2.Left = PictureBox2.Left - 2
    End Sub
    Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
            If e.KeyValue = Keys.W Then
            Timer1.Stop()
            ElseIf e.KeyValue = Keys.A Then
            Timer4.Stop()
            ElseIf e.KeyValue = Keys.S Then
            Timer2.Stop()
            ElseIf e.KeyValue = Keys.D Then
            Timer3.Stop()
        ElseIf e.KeyValue = Keys.Space Then
        End If
    End Sub
    Private Sub Form1_Keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyValue = Keys.W Then
            Timer1.Start()
        ElseIf e.KeyValue = Keys.A Then
            Timer4.Start()
        ElseIf e.KeyValue = Keys.S Then
            Timer2.Start()
        ElseIf e.KeyValue = Keys.D Then
            Timer3.Start()
        ElseIf e.KeyValue = Keys.Space Then
            Me.Controls.Add(PictureBox2)
            PictureBox2 = New PictureBox()
            PictureBox2.Location = New Point(PictureBox1.Location)
            PictureBox2.Size = New Size(15, 15)
            PictureBox2.BackgroundImage = My.Resources.Mg
            PictureBox2.BackgroundImageLayout = ImageLayout.Stretch
            Timer5.Start()
        End If
    End Sub
End Class

Hoffe ihr wisst wo mein denk Fehler ist und ja es ist mir Bewusst das der code nicht ganz fertig geschrieben ist und so mit die Picturebox nicht entfernt wird nach der Ausführung und auch keine zeit Angabe hat wann es entfernt werden müsste so wie das der Timer ständig Aktiv ist und kein Deaktivierung Muster hat es wahr ja bis her nur ein Test es soll einfach nur Erstellt werden auf die Position meiner anderer Picturebox und dann nach links gehen

Bin gespannt auf eure Antwort und ja mir ist auch bewusst das man alles anders und eventuell einfacher machen könnte nur komme ich so am besten kla damit und sry wegen meine Rechtschreibschwäche ^^"
ProDielerNR(1) is offline  
Old 02/01/2017, 19:46   #2
 
mrapc's Avatar
 
elite*gold: 238
Join Date: Sep 2009
Posts: 2,327
Received Thanks: 1,164
Code:
PictureBox2.Left = PictureBox2.Left - 2
So Funktioniert das auch nicht, oder ist das eine WPF Anwendung?

Sonst wäre das ganze:
[CODE]
Picturebox2.location = New Point(PictureBox2.location.Y, PictureBox2.location.X -2)


Du könntest auch Probieren deinen Timer als new Timer zu initalisieren:
Public WithEvents Timer4 As New Timer
mrapc is offline  
Thanks
1 User
Old 02/01/2017, 22:02   #3
 
elite*gold: 0
Join Date: Jan 2013
Posts: 131
Received Thanks: 11
Mrapc ich habe beides versucht doch leider nicht das Ergebnis was ich wollte :?
Sie erstellten sich noch Will Kühler als zuvor :?
und sie bewegten sich auch nicht in die gewünschte Position bzw Richtung :?

Es ist eine neue Form Anwendung in Code Form
Ich hoffe ich konnte diese frage "WPF" hiermit beantworten da ich leider nicht genau weiß
was damit gemeint wahr bzw die Bedeutung von "WPF" ^^"
ProDielerNR(1) is offline  
Old 02/01/2017, 22:48   #4
 
mrapc's Avatar
 
elite*gold: 238
Join Date: Sep 2009
Posts: 2,327
Received Thanks: 1,164
Quote:
Originally Posted by ProDielerNR(1) View Post
Mrapc ich habe beides versucht doch leider nicht das Ergebnis was ich wollte :?
Sie erstellten sich noch Will Kühler als zuvor :?
und sie bewegten sich auch nicht in die gewünschte Position bzw Richtung :?

Es ist eine neue Form Anwendung in Code Form
Ich hoffe ich konnte diese frage "WPF" hiermit beantworten da ich leider nicht genau weiß
was damit gemeint wahr bzw die Bedeutung von "WPF" ^^"
OK I see what you are try to.

Hier einmal der Fertige Code, als kleines Geschenk, arbeite dich da am besten mal durch, auch was dann natürlich Hitboxen etc. angeht, aber damit bist du schon mal auf einem besseren Weg, da ich es so umgeschrieben habe das es mehr als nur eine Kugel geben kann.

Code:
Public Class Form1
    Dim ResourceFilePath As String
    Public WithEvents PictureBox1 As New PictureBox
    Public WithEvents Timer1 As New Timer
    Public WithEvents Timer2 As New Timer
    Public WithEvents Timer3 As New Timer
    Public WithEvents Timer4 As New Timer
    Public WithEvents Timer5 As New Timer
    Public WithEvents Label1 As New Label
    Public Sub New()
        Me.StartPosition = FormStartPosition.CenterScreen
        Me.Text = "Game"
        Me.MaximumSize = New System.Drawing.Size(800, 600)
        Me.MinimumSize = New System.Drawing.Size(800, 600)
        Me.Size = New System.Drawing.Size(800, 600)
        Me.TopMost = True
        Me.BackColor = Color.White
        Label1 = New Label()
        Label1.Size = New Size(200, 80)
        Label1.Location = New Point(340, 470)
        Me.Controls.Add(Label1)
        Label1.ForeColor = Color.OrangeRed
        Label1.BackColor = Color.Transparent
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 20.0!,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
        Label1.Text = "Starten"
        '//Intger Werte niemals als Strings "5" initalisieren
        Timer1.Interval = 5
        Timer2.Interval = 5
        Timer3.Interval = 5
        Timer4.Interval = 5
    End Sub
    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
        Me.BackgroundImage = Nothing
        Me.BackColor = Color.Green
        Me.Controls.Remove(Label1)
        PictureBox1.Size = New Size(40, 66)
        PictureBox1.Location = New Point(355, 249)
        Me.Controls.Add(PictureBox1)
        PictureBox1.BackColor = Color.Black
        PictureBox1.BackgroundImageLayout = ImageLayout.Stretch
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        'Nach Oben Gehen
        PictureBox1.Size = New Size(40, 66)
        PictureBox1.BackColor = Color.Blue
        PictureBox1.BackgroundImageLayout = ImageLayout.Stretch
        PictureBox1.Top = PictureBox1.Top - 1
    End Sub
    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        'Nach Unten Gehen
        PictureBox1.Size = New Size(40, 66)
        PictureBox1.BackColor = Color.Red
        PictureBox1.BackgroundImageLayout = ImageLayout.Stretch
        PictureBox1.Top = PictureBox1.Top + 1
    End Sub
    Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        'Nach Rechts Gehen
        PictureBox1.Size = New Size(40, 66)
        PictureBox1.BackColor = Color.Gray
        PictureBox1.BackgroundImageLayout = ImageLayout.Stretch
        PictureBox1.Left = PictureBox1.Left + 1
    End Sub
    Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
        'Nach Links Gehen
        PictureBox1.Size = New Size(40, 66)
        PictureBox1.BackColor = Color.HotPink
        PictureBox1.BackgroundImageLayout = ImageLayout.Stretch
        PictureBox1.Left = PictureBox1.Left - 1
    End Sub

    Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        If e.KeyValue = Keys.W Then
            Timer1.Stop()
        ElseIf e.KeyValue = Keys.A Then
            Timer4.Stop()
        ElseIf e.KeyValue = Keys.S Then
            Timer2.Stop()
        ElseIf e.KeyValue = Keys.D Then
            Timer3.Stop()
        ElseIf e.KeyValue = Keys.Space Then
        End If
    End Sub
    Private Sub Form1_Keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyValue = Keys.W Then
            Timer1.Start()
        ElseIf e.KeyValue = Keys.A Then
            Timer4.Start()
        ElseIf e.KeyValue = Keys.S Then
            Timer2.Start()
        ElseIf e.KeyValue = Keys.D Then
            Timer3.Start()
        ElseIf e.KeyValue = Keys.Space Then
            Dim NeuerSchuss As New Kugel(PictureBox1.Location.X, PictureBox1.Location.Y + (PictureBox1.Height / 2))
            Me.Controls.Add(NeuerSchuss.PicBox)
        End If
    End Sub

    Public Class Kugel
        Public PicBox As New PictureBox
        Public WithEvents Tmr As New Timer

        Public Sub New(ByVal startX As Integer, ByVal startY As Integer)
            PicBox.Location = New Point(startX, startY)
            PicBox.Width = 5
            PicBox.Height = 5
            PicBox.BackColor = Color.Red
            Tmr.Interval = 5
            Tmr.Start()
        End Sub

        Private Sub MoveLeft(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tmr.Tick
            PicBox.Location = New Point(PicBox.Location.X - 1, PicBox.Location.Y)

            '//Kugeln entfernen wenn sie aus der Form austreten und den speicher wieder freigeben
            If PicBox.Location.X < -PicBox.Width Then
                '//Dispose wird verwendet um speicher zu sparen.
                PicBox.Dispose()
                Tmr.Stop()
                Tmr.Dispose()
            End If
        End Sub

    End Class

End Class
mrapc is offline  
Thanks
2 Users
Old 02/01/2017, 23:02   #5
 
elite*gold: 0
Join Date: Jan 2013
Posts: 131
Received Thanks: 11
Genau so habe ich mir das vorgestellt =)
den Rest schaffe ich was ich noch vor habe ^^
da dein Code ziemlich Übersichtlich ist und gut zu verstehen ist :3

Der Forum kann geschlossen werden

Closed Quest
ProDielerNR(1) is offline  
Reply


Similar Threads Similar Threads
Kontrollieren PictureBox andere PictureBox berührt?
11/20/2013 - .NET Languages - 5 Replies
Hey e*pvp! Ich habe aus Spaß in der Schule ein kleines Spiel angefangen... jedoch hänge ich gerade an einem ziemlich doofen Punkt. Wenn der Spieler den Diamanten berührt, dann soll ein neuer Diamant erstellt werden und die Punkte sollen sich um 1 erhöhen; alles kein Problem eigentlich... aber wie kann ich kontrollieren, ob die 1. PictureBox die 2. PictureBox berührt? Der Spieler ist 32x32 groß, und der Diamant 16x16. (Der Spieler kann nur rauf und runter, also müsste er nur die...
[VB 2010] Web.de Captcha in Picturebox anzeigen lassen
09/18/2012 - .NET Languages - 5 Replies
Hallo Leute, Ich bin gerade an einem Web.de Emailgenerator, bei dem man die Captchas aber manuell eingeben muss. Ich verwende einen Webbrowser, bis das mit dem Captcha funktioniert, dann werde ich in httpwebrequest umcoden. Nun wollte ich fragen, wie man das Captcha in einer Picturebox anzeigen lassen kann?
[VB 2010] Bild aus PictureBox auf FTP Server hochladen
07/15/2011 - .NET Languages - 11 Replies
Wie kann ich ein Bild aus einer PictureBox direkt auf ein FTP Server hochladen ohne sie vorher auf den Computer zu speichern? Ich habe schon viele Codes ausprobiert aber es Funktioniert nicht! Ich habe schon Text oder abgespeicherte Dateien hochgeladen aber Bilder aus einer PictureBox hochladen geht nicht. Ich wäre euch dankbar, wenn ihr mir hilft und den Code schreibt. :)
Visual Basic 2010 - PictureBox
07/05/2011 - .NET Languages - 6 Replies
Hallo, ich möchte ich VB eine versteckte PictureBox auf der Form zufällig mal ganz kurz zeigen und dann wieder verstecken. Z.B. ist da die leere Form und nach ca. 60 Sek. taucht einmal kurz die PictureBox auf und verschwindet dann wieder. Geht das i-wie mit Random?? Danke!:D
[VB 2010] GDI+ in Picturebox
06/26/2011 - .NET Languages - 2 Replies
Hallo Leute, ich habe gerade ein Problem mit GDI+ in VB 2010. Ich hab ne Picture Box in meiner Form und auf diese Picturebox möchte ich mit GDI+ etwas zeichnen. Aber sobald die Form geöfnet wird kommt ein error in dem Steht : "Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt" bei: Dim z as Graphics = Picbox1.createGraphics Ich hoffe ihr könnt mir helfen...



All times are GMT +1. The time now is 13:16.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.