none
C# windows窗体中怎么知道鼠标的坐标??? RRS feed

答案

  •         /// <summary>   
            /// 获取鼠标的坐标   
            /// </summary>   
            /// <param name="lpPoint">传址参数,坐标point类型</param>   
            /// <returns>获取成功返回真</returns>   
            [DllImport("User32")]  
            public extern static bool GetCursorPos(ref Point lpPoint); 
    
            Point p = new Point(1, 1);//定义存放获取坐标的point变量   
            private void timer1_Tick(object sender, EventArgs e)  
            {  
      
                GetCursorPos(ref p);  
                label_mouse.Text = "X:" + p.X + "\r\nY:" + p.Y;    
            } 
    
    


    算神的博客

    2013年12月5日 1:14

全部回复