Below Code Snippet Illustrates basic GDI+ shape like Line, Ellipse and Rectangle. Code Generates Following Output.
Output of below code |
.cs File Code:
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;
using System.Drawing.Drawing2D;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.BackColor = Color.Cornsilk;
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics dc = e.Graphics;
//200,10 is top,left, 50=width, 50=height
// 3 pixels wide
Pen bluePen = new Pen(Color.Blue, 3);
dc.DrawEllipse(bluePen, 200, 10, 50, 50);
Pen greenPen = new Pen(Color.Green,4);
dc.DrawRectangle(greenPen, 200, 60, 50, 50);
Pen redPen1 = new Pen(Color.Red, 2);
dc.DrawLine(redPen1, 210, 110, 210, 150);
Pen redPen2 = new Pen(Color.Red, 2);
dc.DrawLine(redPen2, 240, 110, 240, 150);
Pen redPen3 = new Pen(Color.Red, 2);
dc.DrawLine(redPen3, 200, 60, 150, 80);
Pen redPen4 = new Pen(Color.Red, 2);
dc.DrawLine(redPen4, 250, 60, 300, 40);
}
}
}
0 comments :
Post a Comment