Your Ads Here

Monday, 13 February 2012

Draw X mark into the frame wherever we click the mouse using C#.NET


It helps to draw a point or a mark on the frame when we click the mouse using C#.NET
Keywords: mouse, click, C#.NET, Mouse Movement, Csharp.NET

You have import a Namespace.
using System.Drawing.Drawing2D;

Here the complete 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;
using System.Drawing.Drawing2D;

namespace testc
{
    public partial class Form1 : Form
    { 
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
         
        }

        private void Form1_Click(object sender, EventArgs e)
        {
            Point pt = MousePosition;

            // Convert to screen coordinates.
            pt = this.PointToClient(pt);

            Graphics gr = this.CreateGraphics();
            gr.DrawLine(Pens.Blue, pt.X - 5, pt.Y - 5, pt.X + 5, pt.Y + 5);
            gr.DrawLine(Pens.Blue, pt.X + 5, pt.Y - 5, pt.X - 5, pt.Y + 5);
        } 
    }
}


Note: If you like this post, please be a follower.

No comments:

Post a Comment