다음을 통해 공유


MouseButtons 열거형

정의

어떤 마우스 단추를 눌렀는지 정의하는 상수를 지정합니다.

이 열거형은 멤버 값의 비트 조합을 지원합니다.

public enum class MouseButtons
[System.Flags]
[System.Runtime.InteropServices.ComVisible(true)]
public enum MouseButtons
[System.Flags]
public enum MouseButtons
[<System.Flags>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type MouseButtons = 
[<System.Flags>]
type MouseButtons = 
Public Enum MouseButtons
상속
MouseButtons
특성

필드

Left 1048576

마우스 왼쪽 단추를 눌렀습니다.

Middle 4194304

마우스 가운데 단추를 눌렀습니다.

None 0

마우스 단추를 누르지 않았습니다.

Right 2097152

마우스 오른쪽 단추를 눌렀습니다.

XButton1 8388608

Microsoft IntelliMouse Explorer의 첫 번째 XButton(XBUTTON1)을 눌렀습니다.

XButton2 16777216

Microsoft IntelliMouse Explorer의 두 번째 XButton(XBUTTON2)을 눌렀습니다.

예제

다음 예제에서는 사용 GetCharFromPosition 하는 방법을 보여 줍니다는 지정된 된 컨트롤 좌표의 RichTextBox 내용에서 문자를 가져오는 메서드입니다. 예제 코드는 이벤트 처리기에 매개 변수로 전달된 개체에 있는 MouseEventArgs 좌표를 사용하여 컨트롤의 위치를 결정하여 문자를 가져옵니다. 그런 다음 공백 문자가 아닌 경우 문자가 에 MessageBox 표시됩니다. 이 예제에서는 라는 richTextBox1 컨트롤이 RichTextBox 만들어졌으며 예제 코드가 의 RichTextBox이벤트에 연결되어 MouseDown 있다고 가정합니다.

private:
   void richTextBox1_MouseDown( Object^ /*sender*/, System::Windows::Forms::MouseEventArgs^ e )
   {
      // Determine which mouse button is clicked.
      if ( e->Button == ::MouseButtons::Left )
      {
         // Obtain the character at which the mouse cursor was clicked at.
         Char tempChar = richTextBox1->GetCharFromPosition( Point(e->X,e->Y) );

         // Determine whether the character is an empty space.
         if (  !tempChar.ToString()->Equals( " " ) )

         // Display the character in a message box.
         MessageBox::Show( String::Format( "The character at the specified position is {0}.", tempChar ) );
      }
   }
private void richTextBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
    // Determine which mouse button is clicked.
    if(e.Button == MouseButtons.Left)
    {
        // Obtain the character at which the mouse cursor was clicked at.
        char tempChar = richTextBox1.GetCharFromPosition(new Point(e.X, e.Y));
        // Determine whether the character is an empty space.
        if (tempChar.ToString() != " ")
            // Display the character in a message box.
            MessageBox.Show("The character at the specified position is " + tempChar + ".");
    }
}
Private Sub richTextBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles richTextBox1.MouseDown
    ' Determine which mouse button is clicked.
    If e.Button = MouseButtons.Left Then
        ' Obtain the character at which the mouse cursor was clicked.
        Dim tempChar As Char = richTextBox1.GetCharFromPosition(New Point(e.X, e.Y))
        ' Determine whether the character is an empty space.
        If tempChar <> " " Then
            ' Display the character in a message box.
            MessageBox.Show(("The character at the specified position is " + tempChar + "."))
        End If
    End If
End Sub

다음 예제에서는 다른 마우스 이벤트를 사용하여 에 마우스 경로를 그리는 Panel방법을 보여 줍니다. 선 세그먼트에 추가 되는 GraphicsPath 각각에 대해 MouseMoveMouseDown 발생 하는 이벤트입니다. 그래픽을 업데이트 하는 Invalidate 메서드를 호출 합니다 PanelMouseDownMouseUp 이벤트입니다. 그래픽 경로 위나 아래로 때 스크롤되는 또한는 MouseWheel 이벤트가 발생 합니다. 와 같은 추가 마우스 이벤트가 MouseHover, 화면에서 식별 됩니다. 마우스에 대 한 추가 정보는 화면에 표시 된 SystemInformation 클래스입니다.

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;

namespace MouseEvent
{
   public ref class Form1: public System::Windows::Forms::Form
   {
   private:
      System::Windows::Forms::Panel^ panel1;
      System::Windows::Forms::Label ^ label1;
      System::Windows::Forms::Label ^ label2;
      System::Windows::Forms::Label ^ label3;
      System::Windows::Forms::Label ^ label4;
      System::Windows::Forms::Label ^ label5;
      System::Windows::Forms::Label ^ label6;
      System::Windows::Forms::Label ^ label7;
      System::Windows::Forms::Label ^ label8;
      System::Windows::Forms::Label ^ label9;
      System::Windows::Forms::Button^ clearButton;
      System::Drawing::Drawing2D::GraphicsPath^ mousePath;
      System::Windows::Forms::GroupBox^ groupBox1;
      int fontSize;

   public:
      Form1()
      {
         fontSize = 20;
         mousePath = gcnew System::Drawing::Drawing2D::GraphicsPath;
         this->panel1 = gcnew System::Windows::Forms::Panel;
         this->label1 = gcnew System::Windows::Forms::Label;
         this->clearButton = gcnew System::Windows::Forms::Button;
         this->label2 = gcnew System::Windows::Forms::Label;
         this->label3 = gcnew System::Windows::Forms::Label;
         this->label4 = gcnew System::Windows::Forms::Label;
         this->label5 = gcnew System::Windows::Forms::Label;
         this->label6 = gcnew System::Windows::Forms::Label;
         this->label7 = gcnew System::Windows::Forms::Label;
         this->label8 = gcnew System::Windows::Forms::Label;
         this->label9 = gcnew System::Windows::Forms::Label;
         this->groupBox1 = gcnew System::Windows::Forms::GroupBox;
         
         // Mouse Events Label
         this->label1->Location = System::Drawing::Point( 24, 504 );
         this->label1->Size = System::Drawing::Size( 392, 23 );
         
         // DoubleClickSize Label
         this->label2->AutoSize = true;
         this->label2->Location = System::Drawing::Point( 24, 48 );
         this->label2->Size = System::Drawing::Size( 35, 13 );
         
         // DoubleClickTime Label
         this->label3->AutoSize = true;
         this->label3->Location = System::Drawing::Point( 24, 72 );
         this->label3->Size = System::Drawing::Size( 35, 13 );
         
         // MousePresent Label
         this->label4->AutoSize = true;
         this->label4->Location = System::Drawing::Point( 24, 96 );
         this->label4->Size = System::Drawing::Size( 35, 13 );
         
         // MouseButtons Label
         this->label5->AutoSize = true;
         this->label5->Location = System::Drawing::Point( 24, 120 );
         this->label5->Size = System::Drawing::Size( 35, 13 );
         
         // MouseButtonsSwapped Label
         this->label6->AutoSize = true;
         this->label6->Location = System::Drawing::Point( 320, 48 );
         this->label6->Size = System::Drawing::Size( 35, 13 );
         
         // MouseWheelPresent Label
         this->label7->AutoSize = true;
         this->label7->Location = System::Drawing::Point( 320, 72 );
         this->label7->Size = System::Drawing::Size( 35, 13 );
         
         // MouseWheelScrollLines Label
         this->label8->AutoSize = true;
         this->label8->Location = System::Drawing::Point( 320, 96 );
         this->label8->Size = System::Drawing::Size( 35, 13 );
         
         // NativeMouseWheelSupport Label
         this->label9->AutoSize = true;
         this->label9->Location = System::Drawing::Point( 320, 120 );
         this->label9->Size = System::Drawing::Size( 35, 13 );
         
         // Mouse Panel
         this->panel1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Left | System::Windows::Forms::AnchorStyles::Right);
         this->panel1->BackColor = System::Drawing::SystemColors::ControlDark;
         this->panel1->Location = System::Drawing::Point( 16, 160 );
         this->panel1->Size = System::Drawing::Size( 664, 320 );
         this->panel1->MouseUp += gcnew System::Windows::Forms::MouseEventHandler( this, &Form1::panel1_MouseUp );
         this->panel1->Paint += gcnew System::Windows::Forms::PaintEventHandler( this, &Form1::panel1_Paint );
         this->panel1->MouseEnter += gcnew System::EventHandler( this, &Form1::panel1_MouseEnter );
         this->panel1->MouseHover += gcnew System::EventHandler( this, &Form1::panel1_MouseHover );
         this->panel1->MouseMove += gcnew System::Windows::Forms::MouseEventHandler( this, &Form1::panel1_MouseMove );
         this->panel1->MouseLeave += gcnew System::EventHandler( this, &Form1::panel1_MouseLeave );
         this->panel1->MouseDown += gcnew System::Windows::Forms::MouseEventHandler( this, &Form1::panel1_MouseDown );
         this->panel1->MouseWheel += gcnew System::Windows::Forms::MouseEventHandler( this, &Form1::panel1_MouseWheel );
         
         // Clear Button
         this->clearButton->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right);
         this->clearButton->Location = System::Drawing::Point( 592, 504 );
         this->clearButton->TabIndex = 1;
         this->clearButton->Text = "Clear";
         this->clearButton->Click += gcnew System::EventHandler( this, &Form1::clearButton_Click );
         
         // GroupBox
         this->groupBox1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Left | System::Windows::Forms::AnchorStyles::Right);
         this->groupBox1->Location = System::Drawing::Point( 16, 24 );
         this->groupBox1->Size = System::Drawing::Size( 664, 128 );
         this->groupBox1->Text = "System::Windows::Forms::SystemInformation";
         
         // Set up how the form should be displayed and add the controls to the form.
         this->ClientSize = System::Drawing::Size( 696, 534 );
         array<System::Windows::Forms::Control^>^temp0 = {this->label9,this->label8,this->label7,this->label6,this->label5,this->label4,this->label3,this->label2,this->clearButton,this->panel1,this->label1,this->groupBox1};
         this->Controls->AddRange( temp0 );
         this->Text = "Mouse Event Example";
         
         // Displays information about the system mouse.
         label2->Text = "SystemInformation::DoubleClickSize: {0}",SystemInformation::DoubleClickSize;
         label3->Text = "SystemInformation::DoubleClickTime: {0}",SystemInformation::DoubleClickTime;
         label4->Text = "SystemInformation::MousePresent: {0}",SystemInformation::MousePresent;
         label5->Text = "SystemInformation::MouseButtons: {0}",SystemInformation::MouseButtons;
         label6->Text = "SystemInformation::MouseButtonsSwapped: {0}",SystemInformation::MouseButtonsSwapped;
         label7->Text = "SystemInformation::MouseWheelPresent: {0}",SystemInformation::MouseWheelPresent;
         label8->Text = "SystemInformation::MouseWheelScrollLines: {0}",SystemInformation::MouseWheelScrollLines;
         label9->Text = "SystemInformation::NativeMouseWheelSupport: {0}",SystemInformation::NativeMouseWheelSupport;
      }

   private:
      void panel1_MouseDown( Object^ /*sender*/, System::Windows::Forms::MouseEventArgs^ e )
      {
         // Update the mouse path with the mouse information
         Point mouseDownLocation = Point(e->X,e->Y);
         String^ eventString = nullptr;
         switch ( e->Button )
         {
            case ::MouseButtons::Left:
               eventString = "L";
               break;

            case ::MouseButtons::Right:
               eventString = "R";
               break;

            case ::MouseButtons::Middle:
               eventString = "M";
               break;

            case ::MouseButtons::XButton1:
               eventString = "X1";
               break;

            case ::MouseButtons::XButton2:
               eventString = "X2";
               break;

            case ::MouseButtons::None:
            default:
               break;
         }
         if ( eventString != nullptr )
         {
            mousePath->AddString( eventString, FontFamily::GenericSerif, (int)FontStyle::Bold, (float)fontSize, mouseDownLocation, StringFormat::GenericDefault );
         }
         else
         {
            mousePath->AddLine( mouseDownLocation, mouseDownLocation );
         }

         panel1->Focus();
         panel1->Invalidate();
      }

      void panel1_MouseEnter( Object^ sender, System::EventArgs^ /*e*/ )
      {
         
         // Update the mouse event label to indicate the MouseEnter event occurred.
         label1->Text = String::Concat( sender->GetType(), ": MouseEnter" );
      }

      void panel1_MouseHover( Object^ sender, System::EventArgs^ /*e*/ )
      {
         
         // Update the mouse event label to indicate the MouseHover event occurred.
         label1->Text = String::Concat( sender->GetType(), ": MouseHover" );
      }

      void panel1_MouseLeave( Object^ sender, System::EventArgs^ /*e*/ )
      {
         
         // Update the mouse event label to indicate the MouseLeave event occurred.
         label1->Text = String::Concat( sender->GetType(), ": MouseLeave" );
      }

      void panel1_MouseMove( Object^ /*sender*/, System::Windows::Forms::MouseEventArgs^ e )
      {
         // Update the mouse path that is drawn onto the Panel.
         int mouseX = e->X;
         int mouseY = e->Y;
         mousePath->AddLine( mouseX, mouseY, mouseX, mouseY );
      }

      void panel1_MouseWheel( Object^ /*sender*/, System::Windows::Forms::MouseEventArgs^ e )
      {
         // Update the drawing based upon the mouse wheel scrolling.
         int numberOfTextLinesToMove = e->Delta * SystemInformation::MouseWheelScrollLines / 120;
         int numberOfPixelsToMove = numberOfTextLinesToMove * fontSize;
         if ( numberOfPixelsToMove != 0 )
         {
            System::Drawing::Drawing2D::Matrix^ translateMatrix = gcnew System::Drawing::Drawing2D::Matrix;
            translateMatrix->Translate( 0, (float)numberOfPixelsToMove );
            mousePath->Transform(translateMatrix);
         }

         panel1->Invalidate();
      }

      void panel1_MouseUp( Object^ /*sender*/, System::Windows::Forms::MouseEventArgs^ e )
      {
         Point mouseUpLocation = System::Drawing::Point( e->X, e->Y );
         
         // Show the number of clicks in the path graphic.
         int numberOfClicks = e->Clicks;
         mousePath->AddString( String::Format( "   {0}", numberOfClicks ), FontFamily::GenericSerif, (int)FontStyle::Bold, (float)fontSize, mouseUpLocation, StringFormat::GenericDefault );
         panel1->Invalidate();
      }

      void panel1_Paint( Object^ /*sender*/, System::Windows::Forms::PaintEventArgs^ e )
      {
         // Perform the painting of the Panel.
         e->Graphics->DrawPath( System::Drawing::Pens::DarkRed, mousePath );
      }

      void clearButton_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
      {
         // Clear the Panel display.
         delete mousePath;
         mousePath = gcnew System::Drawing::Drawing2D::GraphicsPath;
         panel1->Invalidate();
      }
   };
}

[STAThread]
int main()
{
   Application::Run( gcnew MouseEvent::Form1 );
}
using System;
using System.Drawing;
using System.Windows.Forms;

namespace MouseEvent
{
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.Panel panel1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.Label label6;
        private System.Windows.Forms.Label label7;
        private System.Windows.Forms.Label label8;
        private System.Windows.Forms.Label label9;
        private System.Windows.Forms.Button clearButton;
        private System.Drawing.Drawing2D.GraphicsPath mousePath;
        private System.Windows.Forms.GroupBox groupBox1;

        private int fontSize = 20;        

        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }

        public Form1()
        {            
            mousePath = new System.Drawing.Drawing2D.GraphicsPath();

            this.panel1 = new System.Windows.Forms.Panel();
            this.label1 = new System.Windows.Forms.Label();
            this.clearButton = new System.Windows.Forms.Button();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.label6 = new System.Windows.Forms.Label();
            this.label7 = new System.Windows.Forms.Label();
            this.label8 = new System.Windows.Forms.Label();
            this.label9 = new System.Windows.Forms.Label();
            this.groupBox1 = new System.Windows.Forms.GroupBox();

            // Mouse Events Label
            this.label1.Location = new System.Drawing.Point(24, 504);
            this.label1.Size = new System.Drawing.Size(392, 23);
            // DoubleClickSize Label
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(24, 48);
            this.label2.Size = new System.Drawing.Size(35, 13);
            // DoubleClickTime Label
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(24, 72);
            this.label3.Size = new System.Drawing.Size(35, 13);
            // MousePresent Label
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(24, 96);
            this.label4.Size = new System.Drawing.Size(35, 13);
            // MouseButtons Label
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(24, 120);
            this.label5.Size = new System.Drawing.Size(35, 13);
            // MouseButtonsSwapped Label
            this.label6.AutoSize = true;
            this.label6.Location = new System.Drawing.Point(320, 48);
            this.label6.Size = new System.Drawing.Size(35, 13);
            // MouseWheelPresent Label
            this.label7.AutoSize = true;
            this.label7.Location = new System.Drawing.Point(320, 72);
            this.label7.Size = new System.Drawing.Size(35, 13);
            // MouseWheelScrollLines Label
            this.label8.AutoSize = true;
            this.label8.Location = new System.Drawing.Point(320, 96);
            this.label8.Size = new System.Drawing.Size(35, 13);
            // NativeMouseWheelSupport Label
            this.label9.AutoSize = true;
            this.label9.Location = new System.Drawing.Point(320, 120);
            this.label9.Size = new System.Drawing.Size(35, 13);

            // Mouse Panel
            this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
                | System.Windows.Forms.AnchorStyles.Right);
            this.panel1.BackColor = System.Drawing.SystemColors.ControlDark;
            this.panel1.Location = new System.Drawing.Point(16, 160);
            this.panel1.Size = new System.Drawing.Size(664, 320);
            this.panel1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseUp);
            this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
            this.panel1.MouseEnter += new System.EventHandler(this.panel1_MouseEnter);
            this.panel1.MouseHover += new System.EventHandler(this.panel1_MouseHover);
            this.panel1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseMove);
            this.panel1.MouseLeave += new System.EventHandler(this.panel1_MouseLeave);
            this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown);
            this.panel1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseWheel);

            // Clear Button
            this.clearButton.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
            this.clearButton.Location = new System.Drawing.Point(592, 504);
            this.clearButton.TabIndex = 1;
            this.clearButton.Text = "Clear";
            this.clearButton.Click += new System.EventHandler(this.clearButton_Click);
            
            // GroupBox
            this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
                | System.Windows.Forms.AnchorStyles.Right);
            this.groupBox1.Location = new System.Drawing.Point(16, 24);
            this.groupBox1.Size = new System.Drawing.Size(664, 128);
            this.groupBox1.Text = "System.Windows.Forms.SystemInformation";

            // Set up how the form should be displayed and add the controls to the form.
            this.ClientSize = new System.Drawing.Size(696, 534);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                        this.label9,this.label8,this.label7,this.label6,
                                        this.label5,this.label4,this.label3,this.label2,
                                        this.clearButton,this.panel1,this.label1,this.groupBox1});
            this.Text = "Mouse Event Example";

            // Displays information about the system mouse.
            label2.Text = "SystemInformation.DoubleClickSize: " + SystemInformation.DoubleClickSize.ToString();
            label3.Text = "SystemInformation.DoubleClickTime: " + SystemInformation.DoubleClickTime.ToString();
            label4.Text = "SystemInformation.MousePresent: " + SystemInformation.MousePresent.ToString();
            label5.Text = "SystemInformation.MouseButtons: " + SystemInformation.MouseButtons.ToString();
            label6.Text = "SystemInformation.MouseButtonsSwapped: " + SystemInformation.MouseButtonsSwapped.ToString();
            label7.Text = "SystemInformation.MouseWheelPresent: " + SystemInformation.MouseWheelPresent.ToString();
            label8.Text = "SystemInformation.MouseWheelScrollLines: " + SystemInformation.MouseWheelScrollLines.ToString();
            label9.Text = "SystemInformation.NativeMouseWheelSupport: " + SystemInformation.NativeMouseWheelSupport.ToString();
        }

        private void panel1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) 
        {
            // Update the mouse path with the mouse information
            Point mouseDownLocation = new Point(e.X, e.Y);

            string eventString = null;
            switch (e.Button) {
                case MouseButtons.Left:
                    eventString = "L";
                    break;
                case MouseButtons.Right:
                    eventString = "R";
                    break;
                case MouseButtons.Middle:
                    eventString = "M";
                    break;
                case MouseButtons.XButton1:
                    eventString = "X1";
                    break;
                case MouseButtons.XButton2:
                    eventString = "X2";
                    break;
                case MouseButtons.None:
                default:
                    break;
            }

            if (eventString != null) 
            {
                mousePath.AddString(eventString, FontFamily.GenericSerif, (int)FontStyle.Bold, fontSize, mouseDownLocation, StringFormat.GenericDefault);
            }
            else 
            {
                mousePath.AddLine(mouseDownLocation,mouseDownLocation);
            }
            panel1.Focus();
            panel1.Invalidate();
        }

        private void panel1_MouseEnter(object sender, System.EventArgs e) 
        {
            // Update the mouse event label to indicate the MouseEnter event occurred.
            label1.Text = sender.GetType().ToString() + ": MouseEnter";
        }

        private void panel1_MouseHover(object sender, System.EventArgs e) 
        {
            // Update the mouse event label to indicate the MouseHover event occurred.
            label1.Text = sender.GetType().ToString() + ": MouseHover";
        }

        private void panel1_MouseLeave(object sender, System.EventArgs e) 
        {
            // Update the mouse event label to indicate the MouseLeave event occurred.
            label1.Text = sender.GetType().ToString() + ": MouseLeave";
        }

        private void panel1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            // Update the mouse path that is drawn onto the Panel.
            int mouseX = e.X;
            int mouseY = e.Y;
            
            mousePath.AddLine(mouseX,mouseY,mouseX,mouseY);
        }

        private void panel1_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            // Update the drawing based upon the mouse wheel scrolling.
      
            int numberOfTextLinesToMove = e.Delta * SystemInformation.MouseWheelScrollLines / 120;
            int numberOfPixelsToMove = numberOfTextLinesToMove * fontSize;

            if (numberOfPixelsToMove != 0) {
                System.Drawing.Drawing2D.Matrix translateMatrix = new  System.Drawing.Drawing2D.Matrix();
                translateMatrix.Translate(0, numberOfPixelsToMove);
                mousePath.Transform(translateMatrix);
            }
            panel1.Invalidate();
        }
        private void panel1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) 
        {
            Point mouseUpLocation = new System.Drawing.Point(e.X, e.Y);
        
            // Show the number of clicks in the path graphic.
            int numberOfClicks = e.Clicks;
            mousePath.AddString("    " + numberOfClicks.ToString(), 
                        FontFamily.GenericSerif, (int)FontStyle.Bold, 
                        fontSize, mouseUpLocation, StringFormat.GenericDefault);

            panel1.Invalidate();
        }

        private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) 
        {    
            // Perform the painting of the Panel.
            e.Graphics.DrawPath(System.Drawing.Pens.DarkRed, mousePath);
        }

        private void clearButton_Click(object sender, System.EventArgs e)
        {
            // Clear the Panel display.
            mousePath.Dispose();
            mousePath = new System.Drawing.Drawing2D.GraphicsPath();
            panel1.Invalidate();
        }
    }
}
Imports System.Drawing
Imports System.Windows.Forms

Namespace MouseEvent
    ' Summary description for Form1.
    Public NotInheritable Class Form1
        Inherits System.Windows.Forms.Form

        Friend WithEvents panel1 As System.Windows.Forms.Panel
        Private label1 As System.Windows.Forms.Label
        Private label2 As System.Windows.Forms.Label
        Private label3 As System.Windows.Forms.Label
        Private label4 As System.Windows.Forms.Label
        Private label5 As System.Windows.Forms.Label
        Private label6 As System.Windows.Forms.Label
        Private label7 As System.Windows.Forms.Label
        Private label8 As System.Windows.Forms.Label
        Private label9 As System.Windows.Forms.Label
        Friend WithEvents clearButton As System.Windows.Forms.Button
        Private mousePath As System.Drawing.Drawing2D.GraphicsPath
        Private groupBox1 As System.Windows.Forms.GroupBox

        Private fontSize As Integer = 20
        
        <System.STAThread()>  _
        Public Shared Sub Main()
            System.Windows.Forms.Application.Run(New Form1())
        End Sub

        Public Sub New()

            mousePath = New System.Drawing.Drawing2D.GraphicsPath()

            Me.panel1 = New System.Windows.Forms.Panel()
            Me.label1 = New System.Windows.Forms.Label()
            Me.clearButton = New System.Windows.Forms.Button()
            Me.label2 = New System.Windows.Forms.Label()
            Me.label3 = New System.Windows.Forms.Label()
            Me.label4 = New System.Windows.Forms.Label()
            Me.label5 = New System.Windows.Forms.Label()
            Me.label6 = New System.Windows.Forms.Label()
            Me.label7 = New System.Windows.Forms.Label()
            Me.label8 = New System.Windows.Forms.Label()
            Me.label9 = New System.Windows.Forms.Label()
            Me.groupBox1 = New System.Windows.Forms.GroupBox()

            ' Mouse Events Label
            Me.label1.Location = New System.Drawing.Point(24, 504) 
            Me.label1.Size = New System.Drawing.Size(392, 23) 
            ' DoubleClickSize Label
            Me.label2.AutoSize = True 
            Me.label2.Location = New System.Drawing.Point(24, 48) 
            Me.label2.Size = New System.Drawing.Size(35, 13) 
            ' DoubleClickTime Label
            Me.label3.AutoSize = True 
            Me.label3.Location = New System.Drawing.Point(24, 72) 
            Me.label3.Size = New System.Drawing.Size(35, 13) 
            ' MousePresent Label
            Me.label4.AutoSize = True 
            Me.label4.Location = New System.Drawing.Point(24, 96) 
            Me.label4.Size = New System.Drawing.Size(35, 13) 
            ' MouseButtons Label
            Me.label5.AutoSize = True 
            Me.label5.Location = New System.Drawing.Point(24, 120) 
            Me.label5.Size = New System.Drawing.Size(35, 13) 
            ' MouseButtonsSwapped Label
            Me.label6.AutoSize = True 
            Me.label6.Location = New System.Drawing.Point(320, 48) 
            Me.label6.Size = New System.Drawing.Size(35, 13) 
            ' MouseWheelPresent Label
            Me.label7.AutoSize = True 
            Me.label7.Location = New System.Drawing.Point(320, 72) 
            Me.label7.Size = New System.Drawing.Size(35, 13) 
            ' MouseWheelScrollLines Label
            Me.label8.AutoSize = True 
            Me.label8.Location = New System.Drawing.Point(320, 96) 
            Me.label8.Size = New System.Drawing.Size(35, 13) 
            ' NativeMouseWheelSupport Label
            Me.label9.AutoSize = True 
            Me.label9.Location = New System.Drawing.Point(320, 120) 
            Me.label9.Size = New System.Drawing.Size(35, 13) 

            ' Mouse Panel
            Me.panel1.Anchor = System.Windows.Forms.AnchorStyles.Top Or _
                                    System.Windows.Forms.AnchorStyles.Left Or _
                                    System.Windows.Forms.AnchorStyles.Right
            Me.panel1.BackColor = System.Drawing.SystemColors.ControlDark
            Me.panel1.Location = New System.Drawing.Point(16, 160)
            Me.panel1.Size = New System.Drawing.Size(664, 320)

            ' Clear Button
            Me.clearButton.Anchor = System.Windows.Forms.AnchorStyles.Top Or _
                                    System.Windows.Forms.AnchorStyles.Right
            Me.clearButton.Location = New System.Drawing.Point(592, 504)
            Me.clearButton.TabIndex = 1
            Me.clearButton.Text = "Clear"

            ' GroupBox
            Me.groupBox1.Anchor = System.Windows.Forms.AnchorStyles.Top Or _
                                  System.Windows.Forms.AnchorStyles.Left Or _
                                  System.Windows.Forms.AnchorStyles.Right
            Me.groupBox1.Location = New System.Drawing.Point(16, 24)
            Me.groupBox1.Size = New System.Drawing.Size(664, 128)
            Me.groupBox1.Text = "System.Windows.Forms.SystemInformation"

            ' Set up how the form should be displayed and add the controls to the form.
            Me.ClientSize = New System.Drawing.Size(696, 534)
            Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.label9, _
                            Me.label8, Me.label7, Me.label6, Me.label5, Me.label4, _
                            Me.label3, Me.label2, Me.clearButton, Me.panel1, Me.label1, Me.groupBox1})

            Me.Text = "Mouse Event Example"

            ' Display information about the system mouse.
            label2.Text = "SystemInformation.DoubleClickSize: " + SystemInformation.DoubleClickSize.ToString()
            label3.Text = "SystemInformation.DoubleClickTime: " + SystemInformation.DoubleClickTime.ToString()
            label4.Text = "SystemInformation.MousePresent: " + SystemInformation.MousePresent.ToString()
            label5.Text = "SystemInformation.MouseButtons: " + SystemInformation.MouseButtons.ToString()
            label6.Text = "SystemInformation.MouseButtonsSwapped: " + SystemInformation.MouseButtonsSwapped.ToString()
            label7.Text = "SystemInformation.MouseWheelPresent: " + SystemInformation.MouseWheelPresent.ToString()
            label8.Text = "SystemInformation.MouseWheelScrollLines: " + SystemInformation.MouseWheelScrollLines.ToString()
            label9.Text = "SystemInformation.NativeMouseWheelSupport: " + SystemInformation.NativeMouseWheelSupport.ToString()
        End Sub

        Private Sub panel1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseDown
            ' Update the mouse path with the mouse information
            Dim mouseDownLocation As New Point(e.X, e.Y)
            
            Dim eventString As String = Nothing
            Select Case e.Button
                Case MouseButtons.Left
                    eventString = "L"
                Case MouseButtons.Right
                    eventString = "R"
                Case MouseButtons.Middle
                    eventString = "M"
                Case MouseButtons.XButton1
                    eventString = "X1"
                Case MouseButtons.XButton2
                    eventString = "X2"
                Case MouseButtons.None:
                     eventString = Nothing              
            End Select
            
            If (eventString IsNot Nothing) Then
                mousePath.AddString(eventString, FontFamily.GenericSerif, CInt(FontStyle.Bold), fontSize, mouseDownLocation, StringFormat.GenericDefault)
            Else
                mousePath.AddLine(mouseDownLocation, mouseDownLocation)
            End If

            panel1.Focus()
            panel1.Invalidate()
        End Sub 
        
        Private Sub panel1_MouseEnter(sender As Object, e As System.EventArgs) Handles panel1.MouseEnter
            ' Update the mouse event label to indicate the MouseEnter event occurred.
            label1.Text = sender.GetType().ToString() + ": MouseEnter"
        End Sub
        
        Private Sub panel1_MouseHover(sender As Object, e As System.EventArgs) Handles panel1.MouseHover
            ' Update the mouse event label to indicate the MouseHover event occurred.
            label1.Text = sender.GetType().ToString() + ": MouseHover"
        End Sub
        
        Private Sub panel1_MouseLeave(sender As Object, e As System.EventArgs) Handles panel1.MouseLeave
            ' Update the mouse event label to indicate the MouseLeave event occurred.
            label1.Text = sender.GetType().ToString() + ": MouseLeave"
        End Sub
        
        Private Sub panel1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseMove
            ' Update the mouse path that is drawn onto the Panel.
            Dim mouseX As Integer = e.X
            Dim mouseY As Integer = e.Y
            
            mousePath.AddLine(mouseX, mouseY, mouseX, mouseY)
        End Sub
        Private Sub panel1_MouseWheel(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseWheel
            ' Update the drawing based upon the mouse wheel scrolling.
            Dim numberOfTextLinesToMove As Integer = CInt(e.Delta * SystemInformation.MouseWheelScrollLines / 120) 
            Dim numberOfPixelsToMove As Integer = numberOfTextLinesToMove * fontSize
            
            If numberOfPixelsToMove <> 0 Then
                Dim translateMatrix As New System.Drawing.Drawing2D.Matrix()
                translateMatrix.Translate(0, numberOfPixelsToMove)
                mousePath.Transform(translateMatrix)
            End If

            panel1.Invalidate()
        End Sub
        Private Sub panel1_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseUp
            Dim mouseUpLocation As New System.Drawing.Point(e.X, e.Y)
            
            ' Show the number of clicks in the path graphic.
            Dim numberOfClicks As Integer = e.Clicks
            mousePath.AddString("     " + numberOfClicks.ToString(), _
                                FontFamily.GenericSerif, CInt(FontStyle.Bold), _
                                fontSize, mouseUpLocation, StringFormat.GenericDefault)

            panel1.Invalidate()
        End Sub
        
        Private Sub panel1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles panel1.Paint
            ' Perform the painting of the Panel.
            e.Graphics.DrawPath(System.Drawing.Pens.DarkRed, mousePath)
        End Sub
        
        Private Sub clearButton_Click(sender As Object, e As System.EventArgs) Handles clearButton.Click
            ' Clear the Panel display.
            mousePath.Dispose()
            mousePath = New System.Drawing.Drawing2D.GraphicsPath()
            panel1.Invalidate()
        End Sub
        
    End Class
End Namespace

설명

이 열거형은 , , , DataGridUpDownBaseControlStatusBarFormSplitterRadioButton및 를 비롯한 AxHost많은 클래스에서 사용됩니다.

적용 대상