Thursday 28 April 2011

Graphics Form Shape in C#


Graphics Form Shape in C#




Set trancperancy key =white

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics grfx = e.Graphics;

            grfx.SmoothingMode = SmoothingMode.HighQuality;

            GraphicsPath grfxPath1 = new GraphicsPath();
           
            Rectangle rec1 = new Rectangle(0, 0, 300, 100);
            grfxPath1.AddEllipse(rec1);
           
            //Rectangle rec2 = new Rectangle(120, 99, 60, 40);
            Rectangle rec2 = new Rectangle(150, 50, 300, 100);
            grfxPath1.AddEllipse(rec2);

            Rectangle rec3 = new Rectangle(00, 100, 300, 100);
            grfxPath1.AddEllipse(rec3);


            grfx.SetClip(grfxPath1, CombineMode.Replace);


            Brush b1 = new SolidBrush(Color.Green);
            Brush b2 = new SolidBrush(Color.Red);
            Brush b3 = new SolidBrush(Color.Blue);
           
            grfx.FillEllipse(b1, rec1);
            grfx.FillEllipse(b2, rec2);
            grfx.FillEllipse(b3, rec3);

            Pen p = new Pen(Color.Yellow, 5f);
            grfx.DrawPath(p, grfxPath1);

        }
    }
}

No comments:

Post a Comment