Sunday, 1 May 2011

Gdi In Win Forms:-




Gdi In Win Forms:-








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

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {  
           // HatchBrush button
            this.Refresh();
            Graphics g;
            g = this.CreateGraphics();
            Rectangle rect = new Rectangle(0,0,this.Width,this.Height);

            HatchBrush hb1 = new HatchBrush(HatchStyle.LightDownwardDiagonal,Color.Purple,Color.Red);

            g.FillEllipse(hb1,rect);
            g.Dispose();
            hb1.Dispose();
        }

        private void button2_Click(object sender, EventArgs e)
        {
           // LinearGradientBrush Button
            this.Refresh();
            Graphics g;
            g = this.CreateGraphics();
            Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);

            LinearGradientBrush lgb1 = new LinearGradientBrush(rect,Color.Purple,Color.Red,50,false);

            g.FillEllipse(lgb1, rect);
            g.Dispose();
            lgb1.Dispose();
        }

        private void button3_Click(object sender, EventArgs e)
        {

            this.Refresh();
            Graphics g;
            g = this.CreateGraphics();
           
            //Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);

            Image img = new Bitmap("C:\\1.jpg");
            g.DrawImage(img,10,10,100,100);
            g.Dispose();
            img.Dispose();
        }

        private void button4_Click(object sender, EventArgs e)
        {
           // PathGradientBrush Button
            this.Refresh();
           
            Graphics g;
            g = this.CreateGraphics();
           
            Point[] pt = { new Point(10, 10), new Point(450, 10), new Point(450, 250), new Point(10, 250) };
                       
            Rectangle rect = new Rectangle(0,0,this.Width,this.Height);
           
            PathGradientBrush pgb=new PathGradientBrush(pt);
          
            pgb.WrapMode = WrapMode.TileFlipXY;
            pgb.CenterColor = Color.Red;
            pgb.SurroundColors = new Color[] { Color.Red,Color.Blue,Color.Chocolate,Color.Crimson};
           
            g.FillRectangle(pgb,rect);

            g.Dispose();
            pgb.Dispose();
            //p.Dispose();
        }
    }
}

No comments:

Post a Comment