hello.. im using vb.net 2003..
ive searched everywhere, the code that provide draw a free line inside picturebox.. which is myself can click anywhere inside the picturebox as first line than extend the line as it reach scond point... ive only found a code that provide value of axis already on coding...the picturebox contain a picture..
Draw a freeline
Page 1 of 17 Replies - 163 Views - Last Post: 30 January 2013 - 12:57 AM
Replies To: Draw a freeline
#2
Re: Draw a freeline
Posted 29 January 2013 - 07:27 PM
I don't know how close VB.NET 2003 is to a more recent version but the code sample below demonstrates drawing a line when dragging:
You'll need to modify it if you want it to happen on clicking two different points.
Private _Previous As System.Nullable(Of Point) = Nothing
Private Sub pictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
_Previous = e.Location
pictureBox1_MouseMove(sender, e)
End Sub
Private Sub pictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
If _Previous IsNot Nothing Then
If PictureBox1.Image Is Nothing Then
Dim bmp As New Bitmap(PictureBox1.Width, PictureBox1.Height)
Using g As Graphics = Graphics.FromImage(bmp)
g.Clear(Color.White)
End Using
PictureBox1.Image = bmp
End If
Using g As Graphics = Graphics.FromImage(PictureBox1.Image)
g.DrawLine(Pens.Black, _Previous.Value, e.Location)
End Using
PictureBox1.Invalidate()
_Previous = e.Location
End If
End Sub
Private Sub pictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp
_Previous = Nothing
End Sub
You'll need to modify it if you want it to happen on clicking two different points.
#3
Re: Draw a freeline
Posted 29 January 2013 - 11:05 PM
andrewsw, on 29 January 2013 - 07:27 PM, said:
I don't know how close VB.NET 2003 is to a more recent version but the code sample below demonstrates drawing a line when dragging:
You'll need to modify it if you want it to happen on clicking two different points.
Private _Previous As System.Nullable(Of Point) = Nothing
Private Sub pictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
_Previous = e.Location
pictureBox1_MouseMove(sender, e)
End Sub
Private Sub pictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
If _Previous IsNot Nothing Then
If PictureBox1.Image Is Nothing Then
Dim bmp As New Bitmap(PictureBox1.Width, PictureBox1.Height)
Using g As Graphics = Graphics.FromImage(bmp)
g.Clear(Color.White)
End Using
PictureBox1.Image = bmp
End If
Using g As Graphics = Graphics.FromImage(PictureBox1.Image)
g.DrawLine(Pens.Black, _Previous.Value, e.Location)
End Using
PictureBox1.Invalidate()
_Previous = e.Location
End If
End Sub
Private Sub pictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp
_Previous = Nothing
End Sub
You'll need to modify it if you want it to happen on clicking two different points.
helo.. regarding you code.. i already try it..but it seem an error occur when i start debug.. something wrong in section if_Previous isnot nothing then.. error describe "is not requires operands that have reference types, but this operand has the value type 'system.nullable(of system.drawing.point)"
#4
Re: Draw a freeline
Posted 29 January 2013 - 11:50 PM
It is not my code, I just found it for illustration. However, I have just copied and run it successfully in VB.NET 2012. So it looks like there is a difference in some syntax between VB 2003 and 2012.
Try splitting it to two separate words, Is Not, or:
Apparently, the IsNot operator was introduced in 2005, so I'm surprised that it accepts it at all. But I think believe the previous code-line is equivalent.
Try splitting it to two separate words, Is Not, or:
If Not _Previous Is Nothing Then
Apparently, the IsNot operator was introduced in 2005, so I'm surprised that it accepts it at all. But I think believe the previous code-line is equivalent.
#5
Re: Draw a freeline
Posted 30 January 2013 - 12:36 AM
i tried to use it on vb.net 2005.. the error still the same, at the same line.. i start from begining..at vb.net 2005.. on empty form, i create picturebox and insert picture.. i didnt modified properties of it.. then go to coding.. copy the code you give to me.. test it and error pop up.. same error.. maybe im miss something or you forgot something to put at the code..
#6
Re: Draw a freeline
Posted 30 January 2013 - 12:46 AM
above code runs perfect in vb2012... but there need so much modification i order to run that in vb2005 coz of changed syntax.
#7
Re: Draw a freeline
Posted 30 January 2013 - 12:55 AM
oh my.. i need more reference if the case like that.. to combine old and new one version.. anyway thanks guys..
#8
Re: Draw a freeline
Posted 30 January 2013 - 12:57 AM
Quote
or you forgot something to put at the code..
He, he - thanks
I just copied the code. It works for me in 2012. I found this code (quite quickly) and offered it to you to illustrate how you might do this, suggesting that you would probably need to modify it for 2003.
I didn't insert an image into the picturebox, and don't know if this would make a difference(?).
Perhaps it is this line:
Private _Previous As System.Nullable(Of Point) = Nothing
which is not acceptable to 2003 (or 2005), but I would have thought it would indicate an error with an underline of some kind.
Anyway, good luck.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|