Sunday, 1 May 2011

Solid Brush In Win Forms:-


Solid Brush 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 Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            // Create brushes
            SolidBrush redBrush = new SolidBrush(Color.Red);
            SolidBrush blueBrush = new SolidBrush(Color.Blue);
            SolidBrush greenBrush = new SolidBrush(Color.Green);

            //Create a rectangle
            Rectangle rect = new Rectangle(80, 80, 50, 50);

            // Fill ellipses
            g.FillEllipse(redBrush , 40.0F, 40.0F, 130.0F, 130.0F);
            g.FillEllipse(greenBrush , 60, 60, 90, 90);
            g.FillEllipse(blueBrush, 80,80,50,50);

            // Dispose of objects
            blueBrush.Dispose();
            redBrush.Dispose();
            greenBrush.Dispose();
        }
    }
}

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();
        }
    }
}

Draw Text On Mouse Move In Win Forms:-



Draw Text On Mouse Move 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 WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        int i, j;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            Graphics g;
            g = this.CreateGraphics();
            Font f = new Font("Arial", 15);

            Pen p = new Pen(new SolidBrush(Color.Red),1);
           
            if (i % 3 == 0)
            {
                g.DrawString("Rajesh", f, new SolidBrush(Color.Purple), new RectangleF(new Point(e.X, e.Y), new SizeF(100, 110)));
            }
           
            i = i + 1;

            this.Text = "Mouse Position :-" + e.X + "," + e.Y;

            f.Dispose();
            g.Dispose();
        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {

        }
    }
}

Create Circles on Mouse Move in Win Forms:-



Create Circles on Mouse Move 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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        int i, j;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            Graphics g;
            g = this.CreateGraphics();
            Font f = new Font("Arial",10);
           
            if (i % 3 == 0)
            {
                g.FillEllipse(new SolidBrush(Color.Red), e.X, e.Y, 50, 50);
            }
            else if (i % 3 == 1)
            {
                g.FillEllipse(new SolidBrush(Color.White), e.X, e.Y, 50, 50);
            }
            else if (i % 3 == 2)
            {
                g.FillEllipse(new SolidBrush(Color.Green), e.X, e.Y, 50, 50);
            }
            i = i + 1;

            this.Text = "Mouse Position :-" + e.X + "," + e.Y;
           
            f.Dispose();
            g.Dispose();
        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                this.Refresh();
            }
        }
    }
}