Drawing lines in Form

K

K.N.Ranjit

Here's my coding again:

Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\Documents and
Settings\rvish\Desktop\trverse.mdb;Persist Security
Info=False")
rs.Open("select Easting,Northing,UserID from
trverse order by cint(UserID)", cn,
ADODB.CursorTypeEnum.adOpenKeyset,
ADODB.LockTypeEnum.adLockOptimistic)
End Sub


Private Sub Form1_Paint(ByVal sender As Object, ByVal
e As System.Windows.Forms.PaintEventArgs) Handles
MyBase.Paint
For i = 0 To rs.RecordCount
x1 = Val(CStr(rs.Fields("Easting").Value))
y1 = Val(CStr(rs.Fields("Northing").Value))
pt = New Point(x1, y1)
rs.MoveNext()
x2 = Val(CStr(rs.Fields("Easting").Value))
y2 = Val(CStr(rs.Fields("Northing").Value))
pt2 = New Point(x2, y2)
e.Graphics.DrawLine(Pens.Green, Me.myconversion
(pt), Me.myconversion(pt2))
Next
rs.Close()
End Sub


Private Function myconversion(ByVal temp As Point) As Point
Return New Point(temp.X, Me.ClientSize.Height -
temp.Y)
End Function

In this case I really know that there is no such error in
my coding.I dont have any design or runtime error,only
thing is that the lines are not been drawn on the form.
I really don't know why.I would be very thankful to anyone
who could point out my mistake if any.I'm facing this
problem b'coz I'm new to this VB.net.
Kindly request u to provide me the coding.
Database : Access and I have plenty of records inside.


Ranjit
 
A

Armin Zingler

K.N.Ranjit said:
Here's my coding again:

Please don't start the same thread again and again. Please answer in one of
the other threads you started!
 
A

Armin Zingler

For i = 0 To rs.RecordCount
x1 = Val(CStr(rs.Fields("Easting").Value))
y1 = Val(CStr(rs.Fields("Northing").Value))
pt = New Point(x1, y1)
rs.MoveNext()
x2 = Val(CStr(rs.Fields("Easting").Value))
y2 = Val(CStr(rs.Fields("Northing").Value))
pt2 = New Point(x2, y2)
e.Graphics.DrawLine(Pens.Green, Me.myconversion
(pt), Me.myconversion(pt2))
Next
rs.Close()

Have you tried setting a breakpoint at the "For" statement, then run your
application til the breakpoint is hit and execute the statements step by
step? What does rs.recordcount return? Did you try examining the values x1,
x2, y1, y2? What are the values of the Point object returned by teh
MyConversion function? What are the data types of the fields "Easting" and
"Northing"? Why do you convert the values to a string, then back to a
numeric variable? Did you enable option strict?

In advance, please answer the questions this time - if possible in *this*
thread. Thank you!
 
B

Brian

Try this: ( If you want to change coordinates without using a function
call you could use the TranslateTransform and ScaleTransform to draw upside
down.)


Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles
MyBase.Paint

Dim x1 as Integer
Dim y1 as Integer
Dim x2 as Integer
Dim y2 as Integer

' --Change coodinates to draw upside down
e.Graphics.TranslateTransform(0, Me.ClientSize.Height)
e.Graphics.ScaleTransform(1, -1)

For i = 0 To rs.RecordCount

x1 = Val(CStr(rs.Fields("Easting").Value))
y1 = Val(CStr(rs.Fields("Northing").Value))
pt = New Point(x1, y1)
rs.MoveNext()
x2 = Val(CStr(rs.Fields("Easting").Value))
y2 = Val(CStr(rs.Fields("Northing").Value))
pt2 = New Point(x2, y2)
e.Graphics.DrawLine(Pens.Green, pt, pt2)

Next
rs.Close()
End Sub
 
R

ranjit narayan

No Armin,I did not enable the option strict.
Then the main thing I got to tell you is that it is only now I had
become a part of the newsgroup by logging in.Now on I shall send the
immediate replies.Bye.
Ranjit
 

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