Results 1 to 24 of 24

Thread: Move

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Move

    Hey guys I was just wondering wat is wrong with this code
    PictureBox2.Location.X = pbX

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Move

    You can not set the X coordinate that way, you have to set the Left property or assign a new Point structure to the Location property.

    The reason why that code is not working is because Location returns a Point structure, and since structures are value-types (the returned Point structure doesnt really have anything to do with the PictureBox' location), you can not assign anything to it. Even if you could, it would be pointless.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: Move

    How do I assign a left property.

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Move

    I'm sorry but have you even tried yourself?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: Move

    yes I have i cant figure it out

  6. #6
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Move

    vb Code:
    1. PictureBox2.Left = 5
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: Move

    When I set a picturebox.right it says it is a read only what do i do to fix this.

  8. #8
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Move

    Where did you see me say anything about the Right property? If I havent been drugged the last 5 minutes, I believe I mentioned the Left property.

    The Right property is a Read-Only property (as you could've easily found out by looking at Intellisense or MSDN) and simply returns the X coordinate for the controls right edge. If you want to change that coordinate, you need to change the Left and/or the Width property.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: Move

    Alright I have fixed that problem. I just looked in some of my older code when i had created a game called pong now here is my code.

    Public Class Form1
    Dim pbX As Integer
    Dim pby As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load



    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Dim objpoint As New System.Drawing.Point(PictureBox2.Location.X, PictureBox2.Location.Y)
    PictureBox2.Location = objpoint
    End Sub

    Private Sub PictureBox2_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles PictureBox2.KeyPress
    If e.KeyChar = "a" Or e.keychar = "A" Then
    Dim objpoint As New System.Drawing.Point(PictureBox2.Location.X - 14, PictureBox2.Location.Y)

    PictureBox2.Location = objpoint
    End If
    End Sub
    End Class

    The only problem is the picture box isnt moving

  10. #10
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Move

    please try this

    PictureBox2.left += 100

    did it move?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  11. #11
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Move

    Here's what MSDN has to say about the PictureBox.KeyPress event:

    This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: Move

    It worked in my old pong game

  13. #13
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Move

    Wouldnt you be better of using the forms KeyDown event instead?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: Move

    how do i

  15. #15
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Move

    Quote Originally Posted by tarik666
    It worked in my old pong game
    What happened when you tried my suggestion?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  16. #16
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Move

    You are already handling the PictureBox' KeyPress event. So obviously you know how to handle an event. Where's the problem?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: Move

    I dont understand what I am meant to do with the keydown event

  18. #18
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Move

    The same thing that you are currently trying to do in the PictureBox' KeyPress event.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: Move

    so do i do like Private Sub PictureBox2_KeyDown or something I dont know

  20. #20
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    Re: Move

    Code:
    Public Sub Form1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.Left Then
            MyPictureBox.Location = New Point(MyPictureBox.Location.X-1, MyPictureBox.Location.Y)
            If MyPictureBox.Location.X < 0 Then
                 MyPictureBox.Location = New Point(0, MyPictureBox.Location.Y)
            End If
        ElseIf e.KeyCode = Keys.Right Then
            MyPictureBox.Location = New Point(MyPictureBox.Location.X+1, MyPictureBox.Location.Y)
            If MyPictureBox.Location.X+MyPictureBox.Width > Form1.Width Then
                 MyPictureBox.Location = New Point(0, MyPictureBox.Location.Y)
            End If
        End If
    End Sub
    Cheers

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: Move

    thanks Icyclur it works fine.

  22. #22
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    Re: Move

    No problem at all [Removed by Mod]

    Cheers
    Last edited by RobDog888; Apr 4th, 2008 at 12:02 PM.

  23. #23

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2007
    Posts
    308

    Re: Move

    I cant their is no edit button

  24. #24
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Move

    Asking someone to read a signature which says to give reps is against the AUP Please edit it or just remove it altogether.

    If someone wants to give you reps, then its up to them to decide to or not to or even give a negative.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width