R4R
Right Place For Right Person TM
R4R C#C# Tutorials
previous

Home

Next

How to Draw Ellipse using mouse dragging in C

How to Draw Ellipse using mouse dragging in C#:

.CS Code

 

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;

namespace WindowsFormsApplication10
{
    public partial class Form1 : Form
    {
        Point start;
        Point end;
        Graphics g;
        bool isDown = false;

        public Form1()
        {
            InitializeComponent();                    
        }
        
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            start = new Point(e.X, e.Y);
            isDown = true;
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if ( isDown )
            {
                g.DrawEllipse(new Pen(Form1.DefaultBackColor, 2), 
		start.X, start.Y, end.X - start.X , end.Y-start.Y);
                end = new Point(e.X, e.Y);
                g.DrawEllipse(new Pen(Color.Black, 2), start.X, start.Y, 
	end.X - start.X, end.Y - start.Y);                
            }            
        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            isDown = false;            
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            g = CreateGraphics();    
        }       
    }
}


Output:

 

previous

Home

Next


Tolal:0 Click:
Show All Comments

Post Your Comments

Your Name:

Your Email ID :
Comments :
URL
  =* Enter SUM

New Updates

R4R
R4R
R4R
R4R
R4R
R4R
R4R
R4R