Project to Draw in VB.NET
Hello Programme...
This code rutines can you help in your problem. You must create a Panel (drawWindow in the code), RadioButtons to draw the Lines, Polygons and Curves and a Button to change the colors (Project from Prentice Hall VB.NET Programing)
The RadioButtons are:
Lines, Polygons,Solid Polygons,Curves,Solid Curves.
Private mPoints As ArrayList = New ArrayList
' initialize default pen and brush
Dim mPen As Pen = New Pen(Color.DarkBlue)
Dim mBrush As SolidBrush = New SolidBrush(Color.DarkBlue)
' draw panel mouse down event handler
Private Sub drawWindow_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles drawWindow.MouseDown
' Add mouse position to vertex list
mPoints.Add(New Point(e.X, e.Y))
drawWindow.Invalidate() ' refresh panel
End Sub ' drawWindow_MouseDown
' draw panel paint event handler
Private Sub drawWindow_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles drawWindow.Paint
' get graphics object for panel
Dim graphicsObject As Graphics = e.Graphics
' if arraylist has 2 or more points, display shape
If mPoints.Count > 1 Then
' get array for use in drawing functions
Dim pointArray() As Point = _
mPoints.ToArray(mPoints(0).GetType())
If polygonRadio.Checked Then ' draw polygon
graphicsObject.DrawPolygon(mPen, pointArray)
ElseIf lineRadio.Checked Then ' draw lines
graphicsObject.DrawLines(mPen, pointArray)
ElseIf filledPolygonRadio.Checked Then ' draw filled
graphicsObject.FillPolygon(mBrush, pointArray)
ElseIf curvaRadio.Checked Then
graphicsObject.DrawCurve(mPen, pointArray) ' Curva
ElseIf FilledCurveRadio.Checked Then
graphicsObject.FillClosedCurve(mBrush, pointArray)
End If
End If
End Sub ' drawWindow_Paint
' handle cmdClear click event
Private Sub cmdClear_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cmdClear.Click
mPoints = New ArrayList ' remove points
drawWindow.Invalidate() ' refresh panel
End Sub ' cmdClear_Click
' handle polygon radio button CheckedChange event
Private Sub polygonRadio_CheckedChanged(ByVal sender As _
System.Object, ByVal e As System.EventArgs) _
Handles polygonRadio.CheckedChanged
drawWindow.Invalidate() ' refresh panel
End Sub ' polygonRadio_CheckedChanged
' handle line radio button CheckChanged event
Private Sub lineRadio_CheckedChanged(ByVal sender As _
System.Object, ByVal e As System.EventArgs) _
Handles lineRadio.CheckedChanged
drawWindow.Invalidate() ' refresh panel
End Sub ' lineRadio_CheckedChanged
' handle filled polygon radio button CheckChanged event
Private Sub filledPolygonRadio_CheckedChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles filledPolygonRadio.CheckedChanged
drawWindow.Invalidate() ' refresh panel
End Sub ' filledPolygonRadio_CheckedChanged
Private Sub CurvaRadio_CheckedChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles curvaRadio.CheckedChanged
drawWindow.Invalidate() ' refresh panel
End Sub ' filledPolygonRadio_CheckedChanged
Private Sub FilledCurveRadio_CheckedChanged(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles FilledCurveRadio.CheckedChanged
drawWindow.Invalidate() ' refresh panel
End Sub ' filledPolygonRadio_CheckedChanged
' handle cmdNewColor click event
Private Sub cmdNewColor_Click(ByVal sender As _
System.Object, ByVal e As System.EventArgs) _
Handles cmdNewColor.Click
' create new color dialog
Dim colorBox As ColorDialog = New ColorDialog
' show dialog and obtain result
Dim result As DialogResult = colorBox.ShowDialog()
' return if user cancels
If result = DialogResult.Cancel Then
Return
End If
mPen.Color = colorBox.Color ' set pen to new color
mBrush.Color = colorBox.Color ' set brush
drawWindow.Invalidate() ' refresh panel
End Sub ' cmdNewColor_Click
I hope this help you...