Results 1 to 5 of 5

Thread: Draw Image On PictureBox At Mouse Position

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2012
    Posts
    5

    Draw Image On PictureBox At Mouse Position

    Hi! It seems I have ran into a small problem. How can you draw an image to a picturebox at the mouse's pointer location. If image can be centered there, that would be
    great! Thanks for any help!

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Draw Image On PictureBox At Mouse Position

    Er ... that doesn't really make sense. What exactly are you trying to do?

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2012
    Posts
    5

    Re: Draw Image On PictureBox At Mouse Position

    I am trying to draw an image on top of the background at a certain location. Is this possible with a picturebox, or do I need another control?

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Draw Image On PictureBox At Mouse Position

    You'll need to decide where to put the various bits of this but this is the basic code you need.

    vb.net Code:
    1. Dim pic As Bitmap = New Bitmap("filename")
    2.         Dim g As Graphics = Graphics.FromHwnd(PictureBox1.Handle)
    3.         g.DrawImage(pic, New Rectangle(sender.PointToClient(MousePosition).X - pic.Width / 2, sender.PointToClient(MousePosition).Y - pic.Height / 2, pic.Width, pic.Height))

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2012
    Posts
    5

    Re: Draw Image On PictureBox At Mouse Position

    Thanks a ton!

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