Draw according to XY path
Draw according to XY path
Draw according to XY path
Draw according to XY path
Draw according to XY path
Draw according to XY path Draw according to XY path Draw according to XY path Draw according to XY path Draw according to XY path Draw according to XY path Draw according to XY path Draw according to XY path
Draw according to XY path Draw according to XY path
Draw according to XY path
Go Back  Xtreme Visual Basic Talk > > > Draw according to XY path


Reply
 
Thread Tools Display Modes
  #1  
Old 10-19-2012, 12:56 PM
AmazingTrans AmazingTrans is offline
Newcomer
 
Join Date: Nov 2005
Posts: 10
Default Draw according to XY path


Hi gurus,

I want to draw a blue lines/dots/points with given moving x & Y coordinates.

I have
X_Draw is the coordinate of X
Y_Draw is the coordinate of Y

I read on the MSDN to use
Dim g As Graphics
Dim graphPath As New GraphicsPath

I am looking for an example to use the points to draw an image..
when i click the button1, it will start drawing with the given X_Draw and Y_Draw...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim g As Graphics
Dim graphPath As New GraphicsPath

...?
End Sub

Last edited by Gruff; 10-30-2012 at 04:14 PM.
Reply With Quote
  #2  
Old 10-19-2012, 02:27 PM
passel's Avatar
passelDraw according to XY path passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

The code you posted is VB.Net code.
You posted in the VB legacy forum, which is for VB4 to 6, VB6 being released in 1998.
I'm going to assume you're not using VB6, but something more like VB.Net 2010.

I don't know that you want to use a GraphicsPath if you're going to be dynamically updating a drawing. A GraphicsPath is most appropriate when you want to collect a series of drawing commands into a single object that you can redraw when desired using a single statement.

Not exactly clear what you want, so I'll throw together a basic drawing example, drawing in a bitmap that backs the form's client area, and see if you can get anything useful from it. Just start a new project and paste the following code into it.
Doesn't use any controls. Just drag the mouse on the background to draw. It draws a big "dot" at the beginning of a line, small red dots at each point in the mouseMove event, and a blue line connecting the points.
Code:
Public Class Form1

  Dim myBitmap As Bitmap           'A bitmap to draw on to keep our graphics from disapearing
  Dim LastX, LastY As Integer      'Track the last point we drew, so we can draw a line from there to a new point

  Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    ResizeBitmap()   'Create the initial bitmap to draw on
    Me.BackColor = Color.White  'Better contrast to see what we're drawing
    Me.DoubleBuffered = True    'Don't like flashing
  End Sub

  Private Sub Form1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
    LastX = e.X
    LastY = e.Y
    Using g As Graphics = Graphics.FromImage(myBitmap)
      g.FillEllipse(Brushes.CadetBlue, LastX - 5, LastY - 5, 11, 11)  'draw a 11 pixel diameter Dot, where we mouse downed
    End Using
    Me.Invalidate()    'have the form update it's drawing area from the bitmap when it can
  End Sub

  Private Sub Form1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
    If e.Button = Windows.Forms.MouseButtons.Left Then 'if we're dragging with the left button then
      Using g As Graphics = Graphics.FromImage(myBitmap)
        g.DrawLine(Pens.Blue, LastX, LastY, e.X, e.Y)                   'Draw a line between the last point and this point
        LastX = e.X
        LastY = e.Y
        g.FillEllipse(Brushes.Red, LastX - 2, LastY - 2, 5, 5)   'draw a smaller ellipse at each point (and a different color
      End Using
      Me.Invalidate()
    End If
  End Sub

  Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    e.Graphics.DrawImage(myBitmap, 0, 0)    'draw the bitmap we're drawing on to the form so we can see it
  End Sub

  Private Sub Form1_Resize(sender As Object, e As System.EventArgs) Handles Me.Resize
    ResizeBitmap()  'create a new bitmap of the current size to draw on
  End Sub

  Private Sub ResizeBitmap()
    Dim lb As New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)  'Create a bitmap the size of the form's client area

    If myBitmap IsNot Nothing Then                     'If we currently have a bitmap
      Using g As Graphics = Graphics.FromImage(lb)     'Get a graphics object for our new bitmap
        g.DrawImage(myBitmap, 0, 0)                    'Draw whatever we have on the existing bitmap to the new bitmap
      End Using
      myBitmap.Dispose()                               'dump the old contents
    End If
    myBitmap = lb                                      'copy the new bitmap reference to the bitmap we use for drawing
  End Sub
End Class
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #3  
Old 10-19-2012, 02:45 PM
AmazingTrans AmazingTrans is offline
Newcomer
 
Join Date: Nov 2005
Posts: 10
Default

passel,

Thank you for your replay.

I have a calculation that draws a circle and it gives out coordinate x& y.
The whole circle has 3600 points of X&Y and each point is populated every 100ms.

I would want a function that reads the pointX and pointY and then use drawcurve to join those lines and form the circle.

I have tried but could not get the lines drawing... :

Code:
Public Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

'Populate circle points into X_Point, Y_Point
'save the previous point into old_X_Point, old_Y_Point

paint_point = True
'call User_define paint function: OnPaint
End Sub

Public Sub OnPaint(ByVal e As PaintEventArgs)
        Dim blackPen As New Pen(Color.Black, 4)
       
        If paint_point = True Then
            '  e.Graphics.DrawLine(myPen, old_X_Point, old_Y_Point, X_Point, Y_Point)
            paint_point = False
        End If
End Sub
Reply With Quote
  #4  
Old 10-19-2012, 03:06 PM
passel's Avatar
passelDraw according to XY path passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Well, I would guess you might want to try to modify what I posted.
Although your "code" is mostly comments, I'll assume your points are fairly close together, and you are drawing directly to the form.
But since the form will be cleared by default for each paint event, you are probably, at most, seeing a small dot traveling around the circle, and not the circle.
Which is why my example draws in a bitmap, then displays the bitmap on the form.
It doesn't matter if the form is erased in preparation for the paint event, I have the previously drawn lines captured in the bitmap, so add the new line segment to the bitmap, and update the form from that bitmap so all historical drawing is present.

Also, that is a pretty slow circle draw. 3600 points at 100ms each, means 6 minutes to draw one complete circle.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 10-19-2012 at 03:12 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Draw according to XY path
Draw according to XY path
Draw according to XY path Draw according to XY path
Draw according to XY path
Draw according to XY path
Draw according to XY path Draw according to XY path Draw according to XY path Draw according to XY path Draw according to XY path Draw according to XY path Draw according to XY path
Draw according to XY path
Draw according to XY path
 
Draw according to XY path
Draw according to XY path
 
-->