Results 1 to 5 of 5

Thread: [RESOLVED] [02/03] Stamping an icon on mouse click - similar to paintbrush

  1. #1

    Thread Starter
    Hyperactive Member scuzymoto's Avatar
    Join Date
    Aug 1999
    Location
    Washington State
    Posts
    316

    Resolved [RESOLVED] [02/03] Stamping an icon on mouse click - similar to paintbrush

    I want a form with an image in the background. I would then like to be able to select one of 5 stamps from a dropdown menu on the side. Then whenever I click on the form it stamps a small image. When all said and done I want to save the form image to a jpg and save it in a database.

    My question is, can someone provide some sample code for stamping icons on a blank form wherever the mouse is clicked. The rest I have figured out.

    Project is for a injury reporting system. A cartoon human body will be displayed on form with type of injury stamped onto the location of injury. This image will accompany an electronically submitted report. I just need help with stamping images onto the form. I have the rest pretty much done including saving an image of the form to a bitmap and then to a database.

    Thanks
    SCUZ

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] Stamping an icon on mouse click - similar to paintbrush

    Take a look at my code for a simple drawing program.

    http://www.vbforums.com/showthread.php?t=426684

    That code keeps a record of the start and end points of lines that get drawn on the form and later saved. You can do basically the same thing but in your case it will be the locations of images. You will use the Graphics.DrawImage method to draw those images where I've used Graphics.DrawLine to draw the lines. The principles are exactly the same though. You just have to determine the most appropriate way to store the control data for the drawing and then how to read it in the Paint event handler.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member scuzymoto's Avatar
    Join Date
    Aug 1999
    Location
    Washington State
    Posts
    316

    Re: [02/03] Stamping an icon on mouse click - similar to paintbrush

    So I've gotten this far from looking at your code. I don't get the rest.

    vb Code:
    1. Private Sub imgInjury_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles imgInjury.MouseDown
    2.  
    3.         Dim g As Graphics = Graphics.FromImage(Me.imgInjury.Image)
    4.         Dim newImage As Bitmap
    5.  
    6.         g.DrawImage(imgWound.Image, e.X, e.Y)

    Where do I go from here? I don't see the wound appearing on the imgInjury picturebox. I have near zero graphics experience in VB. I'm a pure data and database guy. I have saved bitmaps to sql fields before but they were bitmaps already in existance or provided by another source.
    SCUZ

  4. #4

    Thread Starter
    Hyperactive Member scuzymoto's Avatar
    Join Date
    Aug 1999
    Location
    Washington State
    Posts
    316

    Re: [02/03] Stamping an icon on mouse click - similar to paintbrush

    I got it. It was much easier than I thought it was going to be. Thanks for pointing me in the right direction.

    Code:
           
            Dim bm_out As New Bitmap(imgInjury.Image)
            Dim gr_out As Graphics = Graphics.FromImage(bm_out)
    
            gr_out.DrawImage(bm_out, 0, 0)
            gr_out.DrawImage(imgInjuryType.Image, e.X, e.Y)
    
            imgInjury.Image = bm_out
    With each new mouse click the cartoon body gets updated with a new injury type.
    SCUZ

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [02/03] Stamping an icon on mouse click - similar to paintbrush

    Don't forget to dispose your Graphics object when you're done with it. That's very important.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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