Hit Testing : Mouse Event « Event « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# Book
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Event » Mouse EventScreenshots 
Hit Testing
Hit Testing

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using System.Drawing.Drawing2D;

namespace HitTesting
{
    /// <summary>
    /// Summary description for HitTesting.
    /// </summary>
    public class HitTesting : System.Windows.Forms.Form
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;
        private System.Windows.Forms.Label label1;
        
        GraphicsPath gP;
        string mes = "Move to the big I!";
        FontFamily fF = new FontFamily("Times new roman");

        public HitTesting()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            CreateFont();
            this.Text = "Hit Testing";
            this.label1.Font = new Font(fF, 12);
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Disposebool disposing )
        {
            ifdisposing )
            {
                if (components != null
                {
                    components.Dispose();
                }
            }
            base.Disposedisposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(8816);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(16023);
            this.label1.TabIndex = 0;
            this.label1.Text = "label1";
            // 
            // HitTesting
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(513);
            this.ClientSize = new System.Drawing.Size(292109);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.label1});
            this.Name = "HitTesting";
            this.Text = "HitTesting";
            this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.HitTesting_MouseMove);
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new HitTesting());
        }
        void CreateFont()
        {
            Graphics g = this.CreateGraphics();
            label1.Text = mes;
            string s = "I";
            int fSt = (int)FontStyle.Regular;
            Point xy = new Point(5010);
            StringFormat sFr = StringFormat.GenericDefault;
 
            gP = new GraphicsPath();  // gp is a class member
            gP.AddString(s, fF, fSt, 50, xy, sFr);  // add the string to the path
        }

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = this.CreateGraphics();
            g.DrawPath(Pens.Black, gP);  // draw the path to the surface
            g.Dispose();
        }

        private void HitTesting_MouseMove(object sender, MouseEventArgs e)
        {
            Region reg = new Region(gP);
            if(reg.IsVisible(new Point(e.X, e.Y)))
                mes = "You touched me ...";
            else 
                mes = "Move to the big I!";
            CreateFont();
        }
    }
}

           
       
Related examples in the same category
1.Which mouse button was clicked?
2.Mouse left click, right click, middle click, hoverMouse left click, right click, middle click, hover
3.Register Form Mouse Move, down and up actionRegister Form Mouse Move, down and up action
4.Block Mouse
5.Mouse Enter actionMouse Enter action
6.Mouse Exit actionMouse Exit action
7.Mouse click actionMouse click action
8.Mouse Hover actionMouse Hover action
9.Mouse Down actionMouse Down action
10.Mouse up actionMouse up action
11.Mouse Double Click eventMouse Double Click event
12.Handle Mouse click event on an ImageHandle Mouse click event on an Image
13.Catch Mouse Click event inside a strange shapeCatch Mouse Click event inside a strange shape
14.Mouse MovementMouse Movement
15.Mouse Buttons ClickMouse Buttons Click
16.Mouse moveMouse move
17.Full screen and KeyEvent and MouseEvent
18.Mouse HandlerMouse Handler
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.