A pie is a slice of an ellipse. A pie shape also consists of two radial lines that intersect with the endpoints of the arc. Figure 3.30 shows an ellipse with four pie shapes.
The Graphics class provides the DrawPie method, which draws a pie shape defined by an arc of an ellipse. The DrawPie method takes a Pen object, a Rectangle or RectangleF object, and two radial angles.
Let's create an application that draws pie shapes. We create a Windows application and add two text boxes and a button control to the form. The final form looks like Figure 3.31.
The DrawPie button will draw a pie shape based on the values entered in the Start Angle and Sweep Angle text boxes. Listing 3.22 shows the code for the DrawPie button click event handler.
LISTING 3.22: Drawing a pie shape
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Create a Graphics object
Dim g As Graphics = Me.CreateGraphics()
g.Clear(Me.BackColor)
' get the current value of start and sweep angles
Dim startAngle As Single = CSng(Convert.ToDouble(textBox1.Text))
Dim sweepAngle As Single = CSng(Convert.ToDouble(textBox2.Text))
' Create a pen
Dim bluePen As New Pen(Color.Blue, 1)
' Draw pie
g.DrawPie(bluePen, 20, 20, 100, 100, startAngle, _
sweepAngle)
' dispose of objects
bluePen.Dispose()
g.Dispose()
End Sub
End Class
You can try a dll that is around internet, I don't remember the name, but it helps you to make dynamic shapes in asp and vb.net.
ReplyDeletegood luck!