Results 1 to 6 of 6

Thread: Picturebox and other questions

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2009
    Posts
    15

    Question Picturebox and other questions

    Okay this is my code:
    Code:
        Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
            Dim pb As New PictureBox
            pb.Location = e.Location
            pb.ImageLocation = TextBox1.Text
            Me.Controls.Add(pb)
            pb.Height = 32
            pb.Width = 32
    
        End Sub
    It does that you click on something in the form then it will create a Picturebox.
    Okay what I want more is this:

    1. It should only can be made one picture box every 32x32 like this:

    If you dont know what I mean then just forgot it but please try.

    2. When I right click on the mouse the Picturebox should be deleted.

    Thanks for helping!

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Picturebox and other questions

    If you dont know what I mean then just forgot it but please try.
    I'd love to help but I've honestly no idea what you are trying to say with your diagrams.

    I understand your code, that you are creating a new picturebox and the position on the form the user has clicked, and are trying to load the picture specified by the filename in a textbox.

    I have no idea what the diagrams are supposed to mean.

    In order to remove your new picture box when the user right-clicks on it you need to create a routine to handle the mouse-down event and hook it up to your new picture box using AddHandler,

    ie create a routine :

    Code:
    Private Sub RemovePictureBox(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    
            If e.Button = Windows.Forms.MouseButtons.Right Then
                CType(sender, PictureBox).Dispose()
            End If
    
        End Sub
    and in your code which creates the new picture box add the following line :

    Code:
    AddHandler pb.MouseDown, AddressOf RemovePictureBox

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2009
    Posts
    15

    Re: Picturebox and other questions

    Thanks dude Well thats I'am trying to tell is that I want to make a Title editor you know where you put sprites in. Then I want that you can only create sprite every 32x32 that... FORGOT IT LIKE THIS:


    REMEMBER THIS IS: 16x16 couldnt find any with 32x32

  4. #4
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Picturebox and other questions

    Sorry... still not much the wiser, unless what you are saying that the pixture boxes must "snap" to a grid which has cells 32x32 pixels in dimension?

    If that is what you mean then you need to ditch the line

    Code:
    pb.Location = e.Location
    and replace it with something like this

    Code:
    pb.Left = Int(e.X / 32) * 32
    pb.Top = Int(e.Y / 32) * 32
    Problem though : you would potentially end up with multiple picture boxes in the same location though which I'd imagine would be something you want to avoid.

    It might be easier to start off with a two dimensional array of picture boxes to start with rather than creating them dynamically, and that way you can just calculate the X and Y position within the grid and reference the required picture box.

    Otherwise I guess you'll need to loop through the form's control collection and look to see if it already contains a picture box with the co-ordinates you are about to use, and only create the new picture box if there is no match.

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2009
    Posts
    15

    Re: Picturebox and other questions

    THANKS IT WORKED!!! Rep from me. You should really learn me how to explain something

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2009
    Posts
    15

    Re: Picturebox and other questions

    But how do I do that I can example fill it all out you know that I click on click and then the hole screen is filled out with a 32x32 image?

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