Drawing in a VB App

I am developing software for a small eye doctor's office.  Part of the eye exam component requires that the doctor draw (nothing extensive, a few lines or so) a picture of each eye.  I need to incorporate this functionality in the app...namely, there should be a templated bitmap that contains an outline of eye to which the doctor can add his or her graphical input via the mouse.

How would you implement this functionality?  (PS - The graphic must be saved to file so that it can be associated with this exam)
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

yjtConnect With a Mentor Commented:
Paste this in a module:

    Public Function CaptureWindow(ByVal hWndSrc As Long, _
    ByVal Client As Boolean, ByVal LeftSrc As Long, _
    ByVal TopSrc As Long, ByVal WidthSrc As Long, _
    ByVal HeightSrc As Long) As Picture

' CaptureControl      
'    - Captures the Image inside a Control
'    - Returns a Picture object containing a bitmap of the Control's Area

Public Function CaptureControl(Ctl As PictureBox) As Picture

    ' Call CaptureWindow to capture the client area of the form given
    ' its window handle and return the resulting Picture object.
    Set CaptureControl = CaptureWindow(Ctl.hWnd, True, 0, 0, _
    Ctl.ScaleX(Ctl.ScaleWidth, Ctl.ScaleMode, vbPixels), _
    Ctl.ScaleY(Ctl.ScaleHeight, Ctl.ScaleMode, vbPixels))

End Function

Place a picture box call Picsave with autoredraw property to true on a form. Add the eye picture to the picture by assigning it to the picture property.

Add the following declaration at the top of the form
bdrawflag = true

To draw the line, i assume you have your own method or you can simply assign the codes as below:

On the picSave_Mousedown property put :

bDrawflag = True
picSave.PSet (X, Y)

on picSave_Mousemove put:

if bdrawflag = true then

On picSave_Mouseup put:

bdrawflag = false

Then on the form again, add another picbox control named pictemp and assign the scalewidth and scaleheight to 1.
Add a command button to save the modified picture.

On the command1_click event, put:

filename = "C:\Temp.bmp"
Set pictemp.Picture = CaptureControl(picFace)
savepicture pictemp, filename

dfhainesAuthor Commented:
Edited text of question.
dfhainesAuthor Commented:

So far so good...though where is the body of the CaptureWindow function?

I appreciate your generosity.

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

You really do not need to capture the window, just set a picture variable to the picturebox image:

'General Declarations
Private PicTmp As StdPicture

'Save event code
Set PicTmp = picSave.Image
SavePicture PicTmp, "c:\temp.bmp"
dfhainesAuthor Commented:
Thank you yjt and erick37...

Side note Erick37 - Before I received your comment, I did precisely that...though I noticed that the size of the bitmap increased from 7k to 160k with only minor additions.  I saved the initial bitmap template (which I use to prefill the pic control) as a monochrome bitmap.  I don't suppose VB has any way of specifying the type of bitmap?
I believe that the SavePicture method saves as uncompressed BMP.  You could probably find a third party library or picturebox control which would allow you to save as compressed BMP or JPEG.
All Courses

From novice to tech pro — start learning today.