| |

VerySource

 Forgot password?
 Register
Search
View: 647|Reply: 4

C # .Net how to get the relative coordinates when the mouse clicks on the form ???

[Copy link]

3

Threads

11

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-3-9 21:30:02
| Show all posts |Read mode
For example: There is a form of Form1. At runtime. Use your mouse to click anywhere on the Form1 form. To get the relative coordinates of the mouse on the form ??? (note: not the screen coordinates of the mouse click)
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-6-1 10:15:01
| Show all posts
It is recommended to use JS to achieve.
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-6-2 02:00:01
| Show all posts
In the WinForm program, you can use the system.Windows.Forms.Form.MousePosition property to get the mouse, and then subtract the coordinates of the point obtained from the position of the form (Location property) to be the relative position of the mouse.
Reply

Use magic Report

3

Threads

11

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

 Author| Post time: 2020-6-4 11:15:01
| Show all posts
holy1027: Thank you very much. . .
I used your method. But there is a shortcoming. It is when the mouse is pressed to drag the form. If the mouse moves too fast. The movement of the form will not keep up. . .
Is there a good solution in this regard? ? ?
Reply

Use magic Report

0

Threads

14

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-6-4 23:30:01
| Show all posts
If you are in the mouse movement event processing function, you can get it directly
        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            int MousePositionX = e.X
        }
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list