zoukankan      html  css  js  c++  java
  • WPF获取鼠标点击位置和API使用

    private void button2_Click(object sender, RoutedEventArgs e)//获取位置

            {
                POINT p = new POINT();

                Point pp = Mouse.GetPosition(e.Source as FrameworkElement);//WPF方法
                Point ppp = (e.Source as FrameworkElement).PointToScreen(pp);//WPF方法

                if (GetCursorPos(out p))//API方法
                {
                    MessageBox.Show(string.Format("GetCursorPos {0},{1}  GetPosition {2},{3} {4},{5}", p.X, p.Y, pp.X, pp.Y, ppp.X, ppp.Y));
                }
            }

            /// <summary>   
            /// 设置鼠标的坐标   
            /// </summary>   
            /// <param name="x">横坐标</param>   
            /// <param name="y">纵坐标</param>   
            [DllImport("User32")]
            public extern static void SetCursorPos(int x, int y);
            public struct POINT
            {
                public int X;
                public int Y;
                public POINT(int x, int y)
                {
                    this.X = x;
                    this.Y = y;
                }
            }

            /// <summary>   
            /// 获取鼠标的坐标   
            /// </summary>   
            /// <param name="lpPoint">传址参数,坐标point类型</param>   
            /// <returns>获取成功返回真</returns>   
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern bool GetCursorPos(out POINT pt);

    至少证明我们还活着
  • 相关阅读:
    基础--补习汇编笔记--1
    SpProcPool阅读笔记--1
    一般树--common tree
    code-reading-notes--xml 解析
    code-reading-notes--libyang-1
    linux--rbtree 解惑 insert
    记录一次手动杀毒过程
    B-Tree概念
    db2 -- 存储过程01
    sql server 带输入输出参数的分页存储过程(效率最高)
  • 原文地址:https://www.cnblogs.com/pengde/p/8491733.html
Copyright © 2011-2022 走看看