How to prevent the drawing of multiple lines?

G

George

Dear colleagues,
I refer to your help with specific graphic problem. It is
necessary to create a viewfinder in graphic application.
It seems that the algorithm is simple: just draw lines
in specific position in according to value of some

controls, track bars, for example. Next read the track
bars value to find the coordinates of lines cross.
It works, but I can not get real cross because the
background image is being deface by lines images.
The drawing procedures looks like the next:

' Picture box picbView and two track bars (trckHoriz,
trckVer) are created on form.

#Region "Form level variables"
Dim hwnd As New IntPtr ' handler of picturebox's
window
Dim g As Graphics ' graphic object for drawing
lines
#End Region 'Form level variables

Sub InitiateFormData()
' call this procedure at Sub New, located at Windows Form
Designer generated code
' maximums of appropriate trackbars are equal to
picture box size

trckHoriz.Maximum = picbView.Width
trckVert.Maximum = picbView.Height

hwnd = picbView.Handle ' assigned
handler
g = Graphics.FromHwnd(hwnd) ' created
graphic object

' get path to image and load it as picture box's
background
Dim strImageFile As String =
Application.ExecutablePath.Substring(0, _
Application.ExecutablePath.LastIndexOf
("\") + 1) & "Viewfinder.jpg"
picbView.BackgroundImage = Image.FromFile
(strImageFile)

End Sub

Sub DrawViewfinder()
' draw viewfinder's lines

' TODO - how to prevent the drawing of multiple
lines ????

Dim p_en As New Pen(Color.Yellow)
g.DrawLine(p_en, 0, trckVert.Value,
picbView.Width, trckVert.Value) ' horizontal line
g.DrawLine(p_en, trckHoriz.Value, 0,
trckHoriz.Value, picbView.Height) ' vertical line
' and we get the images of all lines ever been
drawn :<<<
End Sub

Private Sub trckHoriz_Scroll(ByVal sender As Object,
ByVal e As System.EventArgs) Handles trckHoriz.Scroll
DrawViewfinder()
End Sub

Private Sub trckVert_Scroll(ByVal sender As Object,
ByVal e As System.EventArgs) Handles trckVert.Scroll
DrawViewfinder()
End Sub


I will be highly grateful for advices how to resolve this
problem.
Best regards
George Golubev, Russia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top