Vector graphics are widely used to draw shapes. You can easily draw shapes in C# applications while working with Aspose.Drawing API. In accordance with such requirements, this article covers how to draw Rectangle in C#.
Create Rectangle Shape - C# API Installation
You need to install Aspose.Drawing for .NET API. Simply configure it from the Downloads section or use the following NuGet command in Microsoft Visual Studio IDE:
PM> Install-Package Aspose.Drawing
Draw a Rectangle in C#
You need to follow the steps below in order to draw a rectangle by following the steps below:
- Initialize a Bitmap class object
- Create a Pen class instance
- Draw the rectangle shape
- Save output drawing image
The code snippet below demonstrates how to draw a rectangle in C#:
Draw a Rectangle in C# - Advanced
You can change different values to customise the rectangle drawing based on your requirements. For example, selecting between the solid brush or texture brush for drawing a rectangle. Please follow the steps below to draw a rectangle with advanced options:
- Initialize a Bitmap class object
- Create a brush while specifying its color
- Create a Pen using the brush
- Draw the rectangle
- Save output drawing image
The code snippet below explains how to draw a rectangle with advanced options in C#:
Get Free Temporary License
You can request a free temporary license to evaluate all the features without any evaluation limitations.
Conclusion
In this article, you have explored how to draw a rectangle while setting different properties programmatically in C#. Moreover, you may visit the documentation section to explore other features included in the API. In case of any queries, feel free to reach out to us at the forum.