| | |
Drawing Multiple Lines
Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2008
Posts: 8
Reputation:
Solved Threads: 0
I'm using the code
To draw a line on a PictureBox. It works fine, until you go to draw another line, when the first line dissapears, i presume this is because i'm using the same integer variables for each one (XPrev, YPrev, XCur, YCur.) How would i be able to use the same integer variables, but be able to draw more than one line ?
VB.NET Syntax (Toggle Plain Text)
Sub PicCanvasMouseDown(sender As Object, e As MouseEventArgs) XPrev = e.X YPrev = e.Y End Sub Sub PicCanvasMouseUp(sender As Object, e As MouseEventArgs) XCur = e.X YCur = e.Y End Sub Sub PicCanvasPaint(sender As Object, e As PaintEventArgs) Dim p As New Pen(Color.Black, 10) Dim g As Graphics = e.Graphics g.DrawLine(p, XPrev, YPrev, XCur, YCur) PicCanvas.Invalidate() End Sub
Yes, I am also meant the same thing.
To draw all the lines you need to store it. so you should have an ArrayList or some other dynamic data structure.
ArrayList can have any object. so you need to group your Line into a class like
Then create a new Line object whenever you draw line.
To repaint, Iterate through the ArrayList and Draw all the Lines in the ArrayList.
This is what i meant.
To draw all the lines you need to store it. so you should have an ArrayList or some other dynamic data structure.
ArrayList can have any object. so you need to group your Line into a class like
VB Syntax (Toggle Plain Text)
Public Class Line Public StartPoint As Point Public EndPoint As Point End Class
Then create a new Line object whenever you draw line.
VB Syntax (Toggle Plain Text)
Sub PicCanvasMouseUp(sender As Object, e As MouseEventArgs) XCur = e.X YCur = e.Y Dim CurLine As New Line CurLine.StartPoint = New Point( XPrev,YPrev) CurLine.EndPoint = e.Location 'Now Add to ArrayList for further use ArrayList.Add ( CurLine ) End Sub
VB Syntax (Toggle Plain Text)
Sub PicCanvasPaint(sender As Object, e As PaintEventArgs) Dim p As New Pen(Color.Black, 10) Dim g As Graphics = e.Graphics 'Here Iterate all the Lines in the ArrayList and Draw It PicCanvas.Invalidate() End Sub
Last edited by selvaganapathy; Sep 13th, 2008 at 3:17 pm.
Selva ![]() |
Similar Threads
- Printing multiple pages, how? (C#)
- Using OpenGL in Visual C++: Part I (Game Development)
- wx.Paint (Python)
- Drawing a line with multiple colors (Java)
- Open Gl Programing Error (help)... (Game Development)
Other Threads in the VB.NET Forum
- Previous Thread: XML generating
- Next Thread: Help with project
Views: 1284 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
"crystal .net .net2005 30minutes 2008 access add application array assignment basic binary box button buttons center code connectionstring convert cpu data database databasesearch datagrid datagridview design designer dissertation dissertations dissertationthesis dll dosconsolevb.net editvb.net employees error excel exists firewall folder function image images isnumericfuntioncall listview login math memory mobile module msaccess mssqlbackend mysql navigate net opacity page pan peertopeervideostreaming picturebox plugin port print printing printpreview problem record refresh reports" reuse save savedialog search serial sorting sql sqldatbase storedprocedure string structures studio temp textbox timer upload useraccounts usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet vista visual visualbasic visualbasic.net visualstudio2008 web wpf xml





