Re: How to do clickable image with overdraw and data storage
- From: "Rick Rothstein \(MVP - VB\)" <rickNOSPAMnews@xxxxxxxxxxxxxxxxx>
- Date: Thu, 26 Apr 2007 11:28:31 -0400
Hi all - here's what I'm trying to do:
I have a form used by physicians to track various patient data.
On one part of this form there is displayed an image of a skeleton
drawing that has a circle to indicate each of the skeletal joints in
the human body.
The physician wants to be able to click each circle joint on the image
that he finds is swollen. When they click on the joint, I need to be
able to fill in the empty circle as a visual indicator on the image
display. I need also to tally the number of swollen joints as they
are clicked/unclicked.
When the doctor closes the form, I need to store the data of which
joints are swollen so that if the form is ever reopened or printed
out, it can use the data to re-overlay the filled-in circles as the
physician has previously indicated. I don't really want to store an
image itself for each patient - I thought it would be more storage-
efficient to have one "background" image and then store the overlay
data in some fashion that could be reproduced upon demand.
We're using VB6. I've been experimenting some with image control and
picture box, and also having a look around to see if there's maybe a
third party control I could purchase that already does something
similar. So far I'm not sure how best to approach this one.
Anyone have advice?
Okay, here is an example of one way to handle your requirement. Start a new
project and add a PictureBox, 3 CommandButtons, a Label and a Shape control
to the form. Follow the instructions below exactly...
For the PictureBox... Make it somewhat large.
For the Label... Name it JointCounter, set its Caption to "0" (zero, no
quote marks), set its Font Size to 18 and then place it off to the side of
the PictureBox
For the CommandButtons... change Command1's Caption to "Save", Command2's
Caption to "Restore" and Command3's Caption to "Clear"; then place them to
the side of the PictureBox also
For the Shape control... Name it JointMarkers (notice the 's' on the end),
change its Shape property to 3-Circle, set its Height and Width properties
to 375 (that should be a comfortable size to work with) and make sure its
FillStyle is set to 1-Transparent (you can also change its FillColor if you
want to work with colored circles instead of black ones). Now, select the
Shape control on the form and press Ctrl+X to Cut it into the Clipboard,
then select the PictureBox and press Ctrl+V to Paste the Shape control into
the PictureBox (you will know if you did this right if you can't drag the
Shape control out of the PictureBox). Now, press Ctrl+V to put another copy
of the Shape control into the PictureBox (you will be asked a question about
creating a Control Array... answer Yes) ... drag this new copy to a
different position on the PictureBox. Now, keep pressing Ctrl+V to place
several more copies of the Shape control onto the Form... the number of them
is up to you (by the way, you will not be asked the question about creating
a Control Array for these other copies... you already answered Yes for the
JointMarkers name for Shape controls).
Okay, now Copy/Paste the code below into the form's code window, run the
project and click away at the various circles you placed around the
PictureBox. Notice the Label control's Caption as you do so. Leaving some of
the circles filled and some not filled, click the CommandButton labeled
"Save". Now click the one labeled "Clear" (this will unfill all of the
circles, similar to what you would have when you start your program for the
first time or when you "load up" a new doctor's account). Now, click the
CommandButton labeled "Restore" to re-fill the circles as they were when you
saved their existing state (make sure you don't click this button before
clicking the Save button... there is no error checking in place in the code
below... that will be up to you to provide in your final program). That's
it... use the ideas here to modify your own project.
Rick
Private Sub Form_Load()
JointCounter.Font.Size = 18
Command1.Caption = "Save"
Command2.Caption = "Restore"
Command3.Caption = "Clear"
End Sub
Private Sub Command1_Click()
SaveJoints "c:\temp\Joints.dat"
End Sub
Private Sub Command2_Click()
ReadJoints "c:\temp\Joints.dat"
End Sub
Private Sub Command3_Click()
Dim Joint As Shape
For Each Joint In JointMarkers
Joint.FillStyle = vbFSTransparent
Next
JointCounter.Caption = 0
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
Dim Joint As Shape
Dim DotWidth As Single
Dim DotHeight As Single
DotWidth = JointMarkers(0).Width
DotHeight = JointMarkers(0).Height
For Each Joint In JointMarkers
With Joint
If (X - (.Left + DotWidth / 2)) * (X - (.Left + DotWidth / 2)) + _
(Y - (.Top + DotHeight / 2)) * (Y - (.Top + DotHeight / 2)) <= _
(DotWidth / 2) * (DotWidth / 2) Then
.FillStyle = 1 - .FillStyle
With JointCounter
If Joint.FillStyle = vbFSSolid Then
.Caption = CStr(CLng(.Caption) + 1)
Else
.Caption = CStr(CLng(.Caption) - 1)
End If
End With
Exit For
End If
End With
Next
End Sub
Sub SaveJoints(FileName As String)
Dim FF As Long
FF = FreeFile
Open FileName For Output As #FF
For X = 0 To JointMarkers.UBound
With JointMarkers(X)
If .FillStyle = vbFSSolid Then
Write #FF, X
End If
End With
Next
Close #FF
End Sub
Sub ReadJoints(FileName As String)
Dim FF As Long
Dim StoredMarker As Long
FF = FreeFile
Open FileName For Input As #FF
Do While Not EOF(FF)
Input #FF, StoredMarker
JointMarkers(StoredMarker).FillStyle = bFSSolid
JointCounter.Caption = CStr(CLng(JointCounter.Caption) + 1)
Loop
Close #FF
End Sub
.
- References:
- How to do clickable image with overdraw and data storage
- From: jennlee_2
- How to do clickable image with overdraw and data storage
- Prev by Date: Re: Placing a command button on the desktop
- Next by Date: Re: Percentage Sign
- Previous by thread: How to do clickable image with overdraw and data storage
- Next by thread: Re: How to do clickable image with overdraw and data storage
- Index(es):
Relevant Pages
|