Your Ads Here

Monday 20 February 2012

To draw ellipse on the form using C#.NET


It shows how to draw ellipse on the form using C#.NET
Keywords: C#.NET, CSharp.NET, form, drawing, graphics.

First import a namespace
using System.Drawing;

Place the code in the paint event for the form.

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 testc
{
    public partial class Form1 : Form
    {
        Graphics gr_graphics = default(Graphics);
        //need a pen for drawing and make it black
        Pen pen_draw = new Pen(Color.Black);

        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
         
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            gr_graphics = e.Graphics;
            //draw an ellipse
            gr_graphics.DrawEllipse(pen_draw, 60, 150, 60, 60);
        }
             
    }
}


No comments:

Post a Comment