Results 1 to 3 of 3

Thread: [RESOLVED] bounding moving image within form

  1. #1

    Thread Starter
    Hyperactive Member Aash's Avatar
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    491

    Resolved [RESOLVED] bounding moving image within form

    hi,
    I've moving image using keyboard, and i want to make this image bound to my form. I mean i don't want to let my image away from the form boundaries. I did it in VB 6 but don't know how to do it in VB.Net, Can anyone please tell me?






    thanks..

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: bounding moving image within form

    how do you mean "bound to my form"?
    if you mean the picturebox must remain within your form's clientrectangle:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    4.         Dim r As Rectangle
    5.         Select Case e.KeyCode
    6.             Case Keys.Left
    7.                 r = New Rectangle(PictureBox1.Left - 10, PictureBox1.Top, 50, 50)
    8.             Case Keys.Right
    9.                 r = New Rectangle(PictureBox1.Left + 10, PictureBox1.Top, 50, 50)
    10.             Case Keys.Up
    11.                 r = New Rectangle(PictureBox1.Left, PictureBox1.Top - 10, 50, 50)
    12.             Case Keys.Down
    13.                 r = New Rectangle(PictureBox1.Left, PictureBox1.Top + 10, 50, 50)
    14.         End Select
    15.         If Me.ClientRectangle.Contains(r) Then
    16.             PictureBox1.Bounds = r
    17.         End If
    18.     End Sub
    19.  
    20. End Class

  3. #3

    Thread Starter
    Hyperactive Member Aash's Avatar
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    491

    Re: bounding moving image within form

    Quote Originally Posted by .paul. View Post
    how do you mean "bound to my form"?
    sorry, i didn't know the exact word to explain the problem but thanks that's what i want.

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