WPF Learning Memo (2) WPF get and set the use of mouse position and ProgressBar

Source: Internet
Author: User

Getting and setting the mouse position in WPF

Method One: WPF method

Point P = mouse.getposition

(e.source as FrameworkElement);
     
Point P = (E.source as FrameworkElement). Pointtoscreen (PP);

Method Two: API method

<summary>///Set Mouse coordinates///</summary>///<param name= "x" > Horizontal coordinate </p
     
        aram>///<param name= "y" > Ordinate </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>///Gets the coordinates of the mouse///</summary>///   
     
     
        <param name= "Lppoint" > Address parameters, coordinate point type </param>///<returns> get successful return True </returns> [DllImport ("user32.dll", CharSet = CharSet.Auto)] public static extern bool GetCursorPos (out Point pt)
     
     
        ; private void Window_mousemove (object sender, MouseEventArgs e) {point P = new POINT (); if (GetCursorPos (out P))//api method {Txtstat.text = string.
            Format ("x:{0} Y:{1}", p.x, P.Y); }
        }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.