简体   繁体   中英

How is the .NET PointToClient function implemented?

My game requires that I call PointToClient every frame, and while this may not be causing any kind of bottleneck currently, I wanted to take a look at the source to see if I could improve the performance of the function. I know that most .NET functions have an awful lot of bloat that can be refactored away, which I have already done with several .NET functions in the past. I looked on the source reference page and found that PointToClient calls NativeWindow.PointToClient, which in turn calls a native function MapWindowPoints.

My question is: How can I view the native source code? And if such a repository is not available, how could this function normally be implemented?

The native method probably does it faster than you can with do with C#. If you really need speed, use DirectX or some gaming API.

This put aside, in order to get the local coordinates (the client coordinates) of a point given in screen coordinates in respect to a control, you must subtract the screen coordinates of this control. In order to get the screen coordinates, add the local coordinates by following the parent's chain up to the form.

It is really not worth the pain to do it yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM