Borderless Window Drag/Move Handling in C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi. I want to have a borderless window which handles mouse clicks in the
normal way. BUT, when the user DRAGs the window (as opposed to clicking it),
I want to start moving the window with the user's drag. How do I determine
when the user is DRAGGING within the window and then how do I handle window
movement based on the user's dragging?

Alex
 
Alex Maghen said:
Hi. I want to have a borderless window which handles mouse clicks in the
normal way. BUT, when the user DRAGs the window (as opposed to clicking
it),
I want to start moving the window with the user's drag. How do I determine
when the user is DRAGGING within the window and then how do I handle
window
movement based on the user's dragging?

<URL:http://dotnetrix.co.uk/misc.html>
-> "Move a borderless form."
-> "An example of a moveable/resizable shaped form."
 
Hi Alex,
Welcome to MSDN Newsgroup!

If we want to do dragaing window with borderless style, we could handle the
WM_NVHITTEST message and return HTCAPTION for this purpose.
The WM_NCHITTEST message will be sent when the mouse is moved through it or
a mouse click is made on it. The function returns one of several enumerated
values, each of which indicates where the mouse action took place. Now one
of these enumerated values is HTCAPTION which indicates that the mouse
action took place on the title bar. So what we do is to verify if the mouse
is currently within the client area of the window, and if it is within the
client area of the window, we check if the mouse is down through a flag
that is set and unset from the LButtonDown and LButtonUp handlers. If all
our checks are passed, we return HTCAPTION, thus fooling the OS into
thinking that the action is taking place on the title bar. It is very
important to verify that the mouse action is within the window'slient area,
otherwise any buttons we have on the title bar, like the close and maximize
buttons will be rendered useless.

I hope the above information is helpful for you. Thanks and have a nice day!

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
 
Back
Top