Mouse Properties : Mouse Event : GUI Windows Forms C# Examples


C# Examples » GUI Windows Forms » Mouse Event »

 

Mouse Properties








    
using  System;
using  System.Drawing;
using  System.Windows.Forms;

public  class  MouseProperties  :  Form
{
    private  Label  lbl;
    int  i  =  0;

    Cursor[]  theCursors  =  {Cursors.AppStarting,  
                            Cursors.Arrow,  
                            Cursors.Hand,  
                            Cursors.Help,  
                            Cursors.No};

    public  MouseProperties()
    {
        Size  =  new  Size(400,600);

        lbl  =  new  Label();
        lbl.Parent  =  this;
        lbl.Location  =  new  Point(50,50);
        lbl.Size  =  new  Size(150,25);
        lbl.BorderStyle  =  BorderStyle.Fixed3D;
        lbl.MouseEnter  +=  new  System.EventHandler(lbl_MouseEnter);
        lbl.MouseHover  +=  new  System.EventHandler(lbl_MouseHover);
        lbl.MouseLeave  +=  new  System.EventHandler(lbl_MouseLeave);
        lbl.MouseDown  +=  new  System.Windows.Forms.MouseEventHandler(lbl_MouseDown);
        lbl.MouseMove  +=  new  System.Windows.Forms.MouseEventHandler(lbl_MouseMove);
        lbl.MouseUp  +=  new  System.Windows.Forms.MouseEventHandler(lbl_MouseUp);
        lbl.MouseWheel  +=  new  System.Windows.Forms.MouseEventHandler(lbl_MouseWheel);
        lbl.Click  +=  new  System.EventHandler(lbl_Click);
        lbl.DoubleClick  +=  new  System.EventHandler(lbl_DoubleClick);

    }

    static  void  Main()  
    {
        Application.Run(new  MouseProperties());
    }

    private  void  lbl_MouseEnter(object  sender,  EventArgs  e)
    {
        lbl.Text  =  "MouseEnter";
        EventArgsStrings();
        lbl.Cursor  =  Cursors.WaitCursor;
    }

    private  void  lbl_MouseHover(object  sender,  EventArgs  e)
    {
        lbl.Cursor  =  theCursors[i  %  5];
        i++;

        lbl.Text  =  "MouseHover";
        EventArgsStrings();
        Console.WriteLine("Label  MouseHover");
    }

    private  void  lbl_MouseLeave(object  sender,  EventArgs  e)
    {
        lbl.Text  =  "MouseLeave";
        EventArgsStrings();
        Console.WriteLine("Label  MouseLeave");
    }

    private  void  lbl_MouseDown(object  sender,  MouseEventArgs  e)
    {
        lbl.Text  =  "MouseDown";
        MouseEventArgsStrings(e);
        Console.WriteLine("Label  MouseDown");
    }

    private  void  lbl_MouseMove(object  sender,  MouseEventArgs  e)
    {
        lbl.Text  =  "MouseMove";
        MouseEventArgsStrings(e);
        Console.WriteLine("Label  MouseMove");
    }

    private  void  lbl_MouseUp(object  sender,  MouseEventArgs  e)
    {
        lbl.Text  =  "MouseUp";
        MouseEventArgsStrings(e);
        Console.WriteLine("Label  MouseUp");
    }

    private  void  lbl_MouseWheel(object  sender,  MouseEventArgs  e)
    {
        lbl.Text  =  "MouseWheel";
        MouseEventArgsStrings(e);
        Console.WriteLine("Label  MouseWheel");
    }

    private  void  lbl_Click(object  sender,  EventArgs  e)
    {
        lbl.Text  =  "Click";
        EventArgsStrings();
        Console.WriteLine("Label  Click");
    }

    private  void  lbl_DoubleClick(object  sender,  EventArgs  e)
    {
        lbl.Text  =  "DoubleClick";
        EventArgsStrings();
        Console.WriteLine("Label  DoubleClick");
    }

    private  void  EventArgsStrings()
    {
        string  str;
        str  =  "\tCursor:    "  +  lbl.Cursor.ToString();
        str  +=  "\r\n\tCapture:    "  +  lbl.Capture.ToString();
        str  +=  "\r\n\tMouseButtons:    "  +  MouseButtons.ToString();
        str  +=  "\r\n\tMousePosition:    "  +  MousePosition.ToString();
        str  +=  "\r\n\tModifierKeys:    "  +  ModifierKeys.ToString();
        Console.WriteLine(str);
    }

    private  void  MouseEventArgsStrings(MouseEventArgs  e)
    {
        string  str;
        str  =  "\tButton:    "  +  e.Button.ToString();
        str  +=  "\r\n\tClicks:    "  +  e.Clicks.ToString();
        str  +=  "\r\n\tDelta:    "  +  e.Delta.ToString();
        str  +=  "\r\n\tX:    "  +  e.X.ToString();
        str  +=  "\r\n\tY:    "  +  e.Y.ToString();
        Console.WriteLine(str);
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo GUI Windows Forms
» Mouse Event