The core of GDI+ functionality is the Graphics class. GDI+ having set of base class from which it can use to make custom drawing on the screen. The set of such class is collectively called the GDI+ managed class interfaces. This class is the part of .NET Framework. It Provides and environment for creating, deploying, and running XML web services and other applications.
The GDI+ managed class interfaces consist of about 60 classes, 50 enumerations, and 8 structures. You can group these class to a various namespaces. Some of are:
- System.Drawing.
- System.Drawing.Drawing.2D
- System.Drawing.Imaging
- System.Drawing.Printing
- System.Drawing.Text
- System.Drawing.Design
Here is the simple window form application:
Make your design page as like this:
Here in this case when user click on first button it will get the shape that we had made in the code behind file using GDI.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Graphics g1 = CreateGraphics();
Pen p = new Pen(Color.Blue, 2);
g1.DrawEllipse(p, 150, 20, 50, 50);
g1.DrawEllipse(p, 160, 35, 10, 10);
g1.DrawEllipse(p, 180, 35, 10, 10);
g1.DrawArc(p, 150, 35, 50, 30, 45, 90);
g1.DrawRectangle(p, 150, 75, 50, 100);
g1.DrawLine(p, 175, 175, 150, 250);
g1.DrawLine(p, 175, 175,200 , 250);
}
private void button2_Click(object sender, EventArgs e)
{
Graphics g2 = CreateGraphics();
SolidBrush sbr = new SolidBrush(Color.Chocolate);
g2.FillEllipse(sbr, 150, 25, 50, 50);
sbr.Color = Color.Gray;
g2.FillEllipse(sbr, 160, 35, 10, 10);
g2.FillEllipse(sbr, 180, 35, 10, 10);
sbr.Color = Color.Black;
g2.FillPie(sbr, 150, 35, 50, 30, 45, 90);
sbr.Color = Color.Bisque;
g2.FillRectangle(sbr, 150, 75, 50, 100);
}
}
}
OUTPUT:
Hope you like it. Thank you for Reading. Have a good day.
No comments:
Post a Comment