A
Ashish
Hi, please take a look at the following code. (I've ommitted the Windows
generated code)
--------------------------------
Imports System.Drawing.Drawing2D
Public Class Form1
Inherits System.Windows.Forms.Form
Dim points() As Point = {}
Dim pen As New Pen(Color.FromArgb(255, 0, 0, 255))
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
If points.Length > 0 Then
e.Graphics.DrawCurve(pen, points)
End If
End Sub
Protected Overrides Sub OnMouseDown(ByVal e As
System.Windows.Forms.MouseEventArgs)
If e.Button = MouseButtons.Right Then
' clear points
ReDim points(-1)
Me.Refresh()
End If
If e.Button = MouseButtons.Left Then
ReDim Preserve points(points.Length)
Dim p As New Point(e.X, e.Y)
points(points.Length - 1) = p
Me.Refresh()
End If
End Sub
End Class
---------------------
On mousedown, the array 'points' gets lengthened by 1 and the curve is
redrawn. But, on exiting from the sub, it gives an InvalidArgumentException.
But if I dont Redim the array, the code runs fine.
Whats going on???
Thanks in advance.
generated code)
--------------------------------
Imports System.Drawing.Drawing2D
Public Class Form1
Inherits System.Windows.Forms.Form
Dim points() As Point = {}
Dim pen As New Pen(Color.FromArgb(255, 0, 0, 255))
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
If points.Length > 0 Then
e.Graphics.DrawCurve(pen, points)
End If
End Sub
Protected Overrides Sub OnMouseDown(ByVal e As
System.Windows.Forms.MouseEventArgs)
If e.Button = MouseButtons.Right Then
' clear points
ReDim points(-1)
Me.Refresh()
End If
If e.Button = MouseButtons.Left Then
ReDim Preserve points(points.Length)
Dim p As New Point(e.X, e.Y)
points(points.Length - 1) = p
Me.Refresh()
End If
End Sub
End Class
---------------------
On mousedown, the array 'points' gets lengthened by 1 and the curve is
redrawn. But, on exiting from the sub, it gives an InvalidArgumentException.
But if I dont Redim the array, the code runs fine.
Whats going on???
Thanks in advance.