Your Ads Here

Tuesday, 21 February 2012

Draw an icon on the form using C#.NET


It shows how to draw icon on the form or draw form icon using C#.NET
Keywords: C#.net, CSharp.NET, icon, 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.DrawIcon (this.Icon ,90,120);
        }
      
    }
}

No comments:

Post a Comment