c# mouse buttons

Ryan C 1 Reputation point
2022-06-22T01:54:11.087+00:00

how do I detect left mouse down for .NET 6.0

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,306 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Castorix31 81,831 Reputation points
    2022-06-22T02:24:39.277+00:00

    A way is with IMessageFilter, like :

        public const int WM_LBUTTONDOWN = 0x0201;  
        public const int WM_LBUTTONUP = 0x0202;  
    
        public Form1()  
        {  
            InitializeComponent();  
            CMessageFilter mf = new CMessageFilter();  
            Application.AddMessageFilter(mf);  
        }  
          
        public class CMessageFilter : IMessageFilter  
        {  
            public bool PreFilterMessage(ref Message m)  
            {                 
                if (m.Msg == WM_LBUTTONDOWN)  
                    Console.Beep(1000, 10);  
                return false;  
            }  
        }  
    
    0 comments No comments

  2. Mamta Nimel 1 Reputation point
    2022-06-25T07:38:45.443+00:00

    if you are working with windows application,
    create mouseDown/mouseUp/mouseClick or Click event for control you wanted to use on
    ,,then check if(e.Button==MouseButton.Left)

    0 comments No comments