PictureBox setzen auf Tastendruck

  • VB.NET

Es gibt 6 Antworten in diesem Thema. Der letzte Beitrag () ist von FuFu^^.

    PictureBox setzen auf Tastendruck

    Hallo,

    ich versuche gerade mit einem Tastendruck (Leertaste), eine Picturebox zu setzen. Doch das will nicht funktionieren. Ich habe auch schon in anderen Foren gesucht, doch da leider nix gefunden...
    Meine Sourcecode:

    VB.NET-Quellcode

    1. Public Class Game
    2. Private Sub Game_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim PicturePlayer As Rectangle Dim PictureBox2 As Rectangle Dim PictureBox3 As Rectangle Dim PictureBox4 As Rectangle Dim PictureBox5 As Rectangle
    3. If PicturePlayer.IntersectsWith(PictureBox2) Then
    4. End If End Sub Friend WithEvents bp As System.Windows.Forms.PictureBox
    5. Private Sub FormKey(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp Dim locationX As Integer Dim locationY As Integer Dim Block As PictureBox
    6. If e.KeyCode = Keys.Up Then PicturePlayer.Location = New Point(PicturePlayer.Location.X, PicturePlayer.Location.Y - 10) ElseIf e.KeyCode = Keys.Down Then PicturePlayer.Location = New Point(PicturePlayer.Location.X, PicturePlayer.Location.Y + 10) ElseIf e.KeyCode = Keys.Right Then PicturePlayer.Location = New Point(PicturePlayer.Location.X + 10, PicturePlayer.Location.Y) ElseIf e.KeyCode = Keys.Left Then PicturePlayer.Location = New Point(PicturePlayer.Location.X - 10, PicturePlayer.Location.Y) ElseIf e.KeyCode = Keys.Escape Then Me.Close() End If
    7. 'Block setzen' If e.KeyCode = Keys.Space Then locationX = PicturePlayer.Location.X + 10 locationY = PicturePlayer.Location.Y + 10 For i As Integer = 1 To 10 Dim pb As New PictureBox pb.Size = New Size(25, 25) pb.Location = New Point(i * locationX, i * locationY) Dim i20 As Integer = 20 * i pb.Image = My.Resources.Stein Me.Controls.Add(pb) Next
    8. MessageBox.Show(locationX, locationY) End If End SubEnd Class


    Ich habe das schonmal selbst versucht, doch das klappt nicht, entweder wird er nicht angezeigt aber gesetzt, oder er wird nicht gesetzt.
    Wie bekomme ich das nun zum laufen?
    Danke für jede Hilfe.

    MfG
    Lukas
    Dateien
    • Game.7z

      (319,48 kB, 92 mal heruntergeladen, zuletzt: )
    So?

    VB.NET-Quellcode

    1. Dim Picturebox1 As PictureBox = New PictureBox
    2. Picturebox1.Location = New Point(100, 100)
    3. Picturebox1.Image = System.Drawing.Image.FromFile("dein pfad hier")
    4. Picturebox1.Width = Picturebox1.Image.Width
    5. Picturebox1.Height = Picturebox1.Image.Height
    6. Me.Controls.Add(Picturebox1)


    edit: hast du dir gestern noch meine codeerweiterung deines codes zu Picturebox Kollisionen angeguckt?

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Derfuhr“ ()

    Lukas97 schrieb:

    Was ist denn GDI? Wie geht das?

    Hier zwei gute GDI Tutorials von FreakJNS

    freakjns.blogspot.de/2011/12/tutorial-vbnet-gdi.html

    und

    freakjns.blogspot.de/2011/11/v…-pen-linien-tutorial.html

    Was FuFu^ ^ sagte ist zwar richtig, aber in dem Maßstab wie dein Spiel
    ist, kann man es noch so machen. Da du glaube ich noch nicht so viel Routine
    beim schreiben hast würde ich dir empfehlen dein Spiel trotzdem fortzusetzen
    damit du erfahrungen sammelst.

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Derfuhr“ ()

    Wenn schon Erfahrung machen, dann bitte richtige. GDI ist nicht zu anspruchsvoll (wenn auch nicht ganz einfach) aber man muss halt ein bisschen Zeit investieren wenn man Resultate will.

    Meine Prognose für die Fortsetzung des akuellen Projekts ist ein unwartbarer Haufen Clusterfuck, durch den er spätestens in 2 Monaten selbst nicht mehr durchsteigt.


    GDI ist nützlich. Die Mühe lohnt sich.
    Oder fang mit WPF an. Das ist zukunftsorientiert.