Home
Explore
Tags
Contribute
Home
»
VB.NET
»
GDI+ IN VB.NET
Drawing Arcs in GDI+ using VB.NET
Posted in
VB.NET
|
GDI+ IN VB.NET
on
November 06, 2019
Tags:
Arcs
,
DrawArc
,
VB.NET
,
ellipse
,
Rectangle
In this article I will explain how to draw arcs in GDI+.
5253
An arc is a portion of an ellipse. For example, Figure 3.12 shows an ellipse that has six arcs. An arc is defined by bounding rectangle (just as an ellipse), a start angle, and a sweep angle. The start angle is an angle in degree measured clockwise from the x-axis to the starting point of the arc.
FIGURE 3.12: Arcs in an ellipse
The sweep angle is an angle in degree measured clockwise from the startAngle parameter to the ending point of the arc. So an arc is the portion of the perimeter of the ellipse between the start angle and the start angle plus the sweep angle.
The DrawArc method draws an arc on a graphics surface. DrawArc takes a pen, a pair of coordinates, a width, and a height.
The Pen object determines the color, width, and style of the arc; Rectangle or RectangleF represents the bounding rectangle; and the last two parameters are the start angle and sweep angle.
To draw an arc, the application creates Pen and Rectangle objects and defines start and sweep angles. Then it calls the DrawArc method.
Let's create an application that will draw an arc to match the values of the start and sweep angles. We create a Windows application, adding add two
text
boxes
and a button control. The final form look like Figure 3.13.
We define two floating variable on the class level to store the start and sweep angles:
FIGURE 3.13: A sample arc application
Private
startAngle
As
Single
= 45.0F
Private
sweepAngle
As
Single
= 90.0F
Note let's draw an arc on the form's pain event handler. Listing 3.11 draws an arc. We first create a pen and a rectangle, and we use them in the DrawArc method with start and sweep angles.
LISTING 3.11: The paint event handler
Private
Sub
Form1_Paint(
ByVal
sender
As
System.Object,
ByVal
e
As
System.Windows.Forms.PaintEventArgs)
Handles
MyBase
.Paint
Dim
redPen
As
New
Pen(Color.Red, 3)
Dim
rect
As
New
Rectangle(20, 20, 200, 200)
e.Graphics.DrawArc(redPen, rect, startAngle, sweepAngle)
redPen.Dispose()
End
Sub
New we add code for the Reset Angles button. Listing 3.12 simply sets the start and sweep angles by reading values from the text boxes and calls the Invalidate method, which forces GDI+ to call the form's paint event handler:
LISTING 3.12: The Reset Angles button click event handler
Private
Sub
ResetAnglesBtn_Click(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
startAngle =
CSng
(Convert.ToDouble(textBox1.Text))
sweepAngle =
CSng
(Convert.ToDouble(textBox2.Text))
Invalidate()
End
Sub
Figure 3.14 shows the default output from the application
Now let's change the start and sweep angles to 90 and 180 degrees, respectively, and click the Reset Angles button. The new output looks like Figure 3.15.
FIGURE 3.14: The default arc, with start angle 45 degrees and sweep angle with 90 degree
FIGURE 3.15: An arc with start angle 90 degrees and sweep angle of 180 degrees
Let's changes angles one more time. This time our start angle will be 180 degrees, and the sweep angle will be 360 degrees. The new output looks like Figure 3.16.
Conclusion
Hope the article would have helped you in understanding how to to draw arcs in GDI+. Read other articles on GDI+ on the website.
Related Articles
WPF Column Chart in VB.NET
Image Animation in VB.NET using GDI+
Select Method carefully in GDI+ using VB.NET
Drawing Simple Graphics in VB.NET
WPF Grid Using VB.NET
Graphics in VB.NET using Handle
WPF Scatter Chart in VB.NET
WPF Line Chart in VB.NET
Drawing Icons in GDI+ using VB.NET
Drawing GDI+ Images on the Web in VB.NET
Categories
ACTIVE DIRECTOTRY IN VB.NET
ALGORITHMS AND VB.NET
ARRAY IN VB.NET
ASP.NET AJAX IN VB.NET
ASP.NET USING VB.NET
ASSEMBLIES IN VB.NET
COM INTEROP IN VB.NET
CRYPTOGRAPHY IN VB.NET
CRYSTAL REPORTS IN VB.NET
DATABASE & DBA
DEPLOYMENT IN VB.NET
DESIGN & ARCHITECTURE
DIRECTX WITH VB.NET
ENTERPRISE DEVELOPMENT
FILE IN VB.NET
GAMES IN VB.NET
GDI+ IN VB.NET
GENERAL
LINQ WITH VB.NET
MOBILE DEV IN VB.NET
MULTITHREADING IN VB.NET
NETWORKIN WITH VB.NET
OFFICE AND VB.NET
PRINTING IN VB.NET
REMOTING IN VB.NET
REPORTS IN VB.NET
SECURITY IN VB.NET
SILVERLIGHT USING VB.NET
Speech in VB.NET
STRING IN VB.NET
TABLET PC
VB.NET ADO.NET
VB.NET ARTICLE
VB.NET EXCEPTION HANDLING
VB.NET FAQ
VB.NET HOW DO I
VB.NET LANGUAGE
VB.NET TUTORIALS
VB.NET WINDOWS SERVICES
VBA
VISUAL BASIC 10
VISUAL BASIC LANGUAGE
WCF WITH VB.NET
WEB CONTROL IN VB.NET
WEB DEV IN VB.NET
WEB FORM WITH VB.NET
WEB SERVICES IN VB.NET
WINDOWS CONTROLS
WINDOWS FORMS IN VB.NET
WORKFLOW IN VB.NET
WPF IN VB.NET
XAML IN VB.NET
XML IN VB.NET
More Articles
Stroke Caps in GDI+ using VB.NET
Basic GDI+ Objects in VB.NET
Transformation in GDI+ in VB.NET
Drawing Images in GDI+ in VB.NET
Working with GDI+ Fonts in VB.NET
GDI+ Pie Chart in VB.NET
Using GDI+ Graphics Paths in VB.NET
Drawing Lines in GDI+ using VB.NET
Printing Text in GDI+ using VB.NET
Designing GUI Applications in GDI+ using VB.NET
Printer Settings in GDI+ and VB.NET
No GDI Calls between GetHdc and ReleaseHdc in VB.NET
GDI Managed Environment in VB.NET
Use GDI+ System Brushes and Pens in VB.NET
Select Method carefully in GDI+ using VB.NET
Use Graphics Paths in GDI+ using VB.NET
SetStyle Method in GDI+ using VB.NET
Overriding the GDI+ OnPaint Method in VB.NET
GDI+ Double Buffering and Flicker-Free Drawing in VB.NET
GDi+ Scope and Type of Variable and Performance in VB.NET
Add GDI+ Paint Event Handler and Controls in VB.NET
Understanding the GDI+ Paint Event in VB.NET
Create ASP .NET Web Application in GDI+ using VB.NET
Working with Text and Strings in VB.NET
GDI+ Transforming Text in VB.NET
GDI+ LinearGradientBrush and PathGradientBrush in VB.NET
Drawing GDI+ Images on the Web in VB.NET
Drawing Simple Graphics in VB.NET
Graphics Web Application in GDI+ usnig VB.NET
Adding GDI+ Web Controls to a Web Form in VB.NET
Customizing Page Settings in GDI+ using VB.NET
DetailsCustom Controlling and Print Controller in VB.NET
Drawing Graphics Shapes in VB.NET
The DocumentName Property and Marginal Printing in VB.NET
Draw 2D graphics line,tringle,ellipse,polygon in VB.NET
Print Dialogs in GDI+ using VB.NET
Printing Graphics in GDI+ using VB.NET
Printing Text in GDI+ using VB.NET
A GDI+ Printer Settings Example in VB.NET
GDI+ Pinting Application in VB.NET
Printer Settings in GDI+ using VB.NET
GDI+ PaperSize Class in VB.NET
Printing in GDI+ using VB.NET
GDI+ Text Transformation in VB.NET
Color Transformation and the Color Matrix in VB.NET
Image Transformation in GDI+ using VB.NET
GDI+ Scaling, Shearing and Rotating Colors in VB.NET
GDI+ Miscellaneous Advanced 2D Topics in VB.NET
Mixed Blending in GDI+ using VB.Net
Compositing Mode and Blending in VB.NET
© 2020 DotNetHeaven. All rights reserved.
TERMS & CONDITIONS
|
CONTACT US
|
REPORT ABUSE