Thursday, 28 April 2011

GDI Operation in Picture Box




GDI Operation in Picture Box 




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
    {
        Graphics g;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog opndlg = new OpenFileDialog();

            opndlg.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";

            if (opndlg.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.Image = new Bitmap(opndlg.FileName);
                this.Text = opndlg.FileName;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
           
            g = pictureBox1.CreateGraphics();
            Pen pen1 = new Pen(new SolidBrush(Color.Red),2);
            g.DrawLine(pen1, 250, 50, 400, 200);
        }
       
       

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button8_Click(object sender, EventArgs e)
        {
            pictureBox1.Refresh();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            System.Drawing.Point[] p = new System.Drawing.Point[6];
            p[0].X = 0;
            p[0].Y = 0;
            p[1].X = 53;
            p[1].Y = 111;
            p[2].X = 114;
            p[2].Y = 86;
            p[3].X = 34;
            p[3].Y = 34;
            p[4].X = 165;
            p[4].Y = 7;
            g = pictureBox1.CreateGraphics();
            Pen pen1 = new Pen(new SolidBrush(Color.Red), 2);
            g.DrawPolygon(pen1, p);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            g = pictureBox1.CreateGraphics();
            Pen pen1 = new Pen(new SolidBrush(Color.Red), 2);
            g.DrawPie(pen1, 50, 50, 150, 150, 0, 170);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            g = pictureBox1.CreateGraphics();
            Pen pen1 = new Pen(new SolidBrush(Color.Red), 2);
            g.DrawArc(pen1, 150, 100, 150, 200, 150, 160);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            g = pictureBox1.CreateGraphics();
            Pen pen1 = new Pen(new SolidBrush(Color.Red), 2);
            g.DrawRectangle(pen1, 30, 30, 50, 60);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            g = pictureBox1.CreateGraphics();
            Pen pen1 = new Pen(new SolidBrush(Color.Red), 2);
            g.DrawEllipse(pen1, 50, 50, 100, 150);
        }
       
    }
}

No comments:

Post a Comment