Mouse Button Left clicked : Mouse Event « GUI Windows Forms « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » GUI Windows Forms » Mouse Event 
23.62.5.Mouse Button Left clicked
using System;
using System.Drawing;
using System.Windows.Forms;
   
class MouseConnect: Form
{
     const int iMaxPoints = 1000;
     int       iNumPoints = 0;
     Point[]   apoint     = new Point[iMaxPoints];
   
     public static void Main()
     {
          Application.Run(new MouseConnect());
     }
     public MouseConnect()
     {
     }
     protected override void OnMouseDown(MouseEventArgs mea)
     {
          if (mea.Button == MouseButtons.Left)
          {
               iNumPoints = 0;
               Invalidate();
          }
     }
     protected override void OnMouseMove(MouseEventArgs mea)
     {
          if (mea.Button == MouseButtons.Left)
          {
               apoint[iNumPoints++new Point(mea.X, mea.Y);
   
               Graphics grfx = CreateGraphics();
               grfx.DrawLine(new Pen(ForeColor), mea.X, mea.Y, 
                                                 mea.X, mea.Y + 1);
               grfx.Dispose();
          }
     }
     protected override void OnMouseUp(MouseEventArgs mea)
     {
          if (mea.Button == MouseButtons.Left)
               Invalidate();
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          Graphics grfx = pea.Graphics;
          Pen      pen  = new Pen(ForeColor);
   
          for (int i = 0   ; i < iNumPoints - 1; i++)
               for (int j = i + 1; j < iNumPoints; j++)
                    grfx.DrawLine(pen, apoint[i], apoint[j]);
    }
}
23.62.Mouse Event
23.62.1.Mouse Event information
23.62.2.Mouse PropertiesMouse Properties
23.62.3.Mouse event handlersMouse event handlers
23.62.4.Mouse Enter / Hover / LeaveMouse Enter / Hover / Leave
23.62.5.Mouse Button Left clicked
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.