c# mouse buttons

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

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.
6,923 questions
{count} votes

2 answers

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

    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;  
            }  
        }  
    
    No comments

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

    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)

    No comments