468,139 Members | 1,455 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,139 developers. It's quick & easy.

How to prevent the drawing of multiple lines?

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
Nov 20 '05 #1
2 1932
Hi,

http://www.vb-helper.com/howto_net_rubberband_line.html

Ken
--------------
"George" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
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

Nov 20 '05 #2
* "Ken Tucker [MVP]" <vb***@bellsouth.net> scripsit:
http://www.vb-helper.com/howto_net_rubberband_line.html


Notice that the 'ControlPaint' class provides some methods to draw
selection rectangles and/or focus rectangles too.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Remon Huijts | last post: by
9 posts views Thread by davetelling | last post: by
4 posts views Thread by Galen Somerville | last post: by
4 posts views Thread by =?Utf-8?B?R2lkaQ==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.