Ad

Saturday, February 1, 2014

Implement a Windows Program To Change the Shapes of the form in C#.Net

In this article i would like to publish an article that Implement a Windows Program To Change the Shapes of the form in C#.Net


Explanation:
For implementation of this we are using a namespace known as
Using System.Drawing.Drawing2D;

Where it can import the different shapes of our real world object like a circle,lines,curves etc...
It can be possible with GraphicsPath class.By using that we can impelement different shapes by passing the  appropriate height,width i.e x,y axis so that we can able to visualize our desired Shapes.

Program:

Step1:Design the Form as Shown Below:





















Step 2:Implement the Code in .Cs Page


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 Graphics
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int i = comboBox1.SelectedIndex;
            GraphicsPath g = new GraphicsPath();
            if (i == 0)
                g.AddEllipse(10, 12, 250, 250);//Displaying of Circle
            else if (i == 1)
                g.AddEllipse(10, 13, 200, 500);//Displaying of Ellipse
            else  //Displaying of Traingle i.e Closed Curve of 3 lines
            {
                g.AddLine(10, 10, 250, 300);//First Line
                g.AddLine(250, 300, 150, 100);//Second Line
                g.AddLine(150, 100, 10, 10);//Third Line
            }
            Region r = new Region(g);
            this.Region = r;
        }
    }
}


Output:


No comments: