 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
qyte Guest
|
Posted: Wed Mar 16, 2005 12:11 am Post subject: Form Dragging??? |
|
|
Is there a way to drag a form that it's BorderStyle is bsNone?
I tried some things with onmousedown etc events but nothing happens.
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Wed Mar 16, 2005 9:09 am Post subject: Re: Form Dragging??? |
|
|
qyte <gyte (AT) vivodinet (DOT) gr> wrote:
| Quote: |
Is there a way to drag a form that it's BorderStyle is bsNone?
|
Sure.
| Quote: | I tried some things with onmousedown etc events but nothing happens.
|
The OnMouseDown and OnMouseMouse events both pass in X and Y
parameters which represent the left,top where the mouse is,
relative to the control, at the time of the event.
The theory is simple: Record the starting click point in the
OnMouseDown and compare that position in the OnMouseMove to
determine if and how much to move the object. Then save the
new position as the click point so that you have something
valid to compare with the next OnMouseMove.
TPoint ClickPoint;
//-------------------------------------------------------------
void __fastcall TForm1::MouseDown(TMouseButton Button, TShiftState Shift, int X, int Y)
{
ClickPoint = Point( X, Y );
}
//-------------------------------------------------------------
void __fastcall TForm1::MouseMove(TShiftState Shift, int X, int Y)
{
if( Shift.Contains(ssLeft) )
{
// compare X,Y with ClickPoint.x,ClickPoint.y
// adjust the position
ClickPoint = Point( X, Y );
}
}
//-------------------------------------------------------------
The catch here is that you have to have an object with which
to implement these events. If you want to use the TForm
OnMouseDown/Move, you'll need to leave a blank space so that
the user can actually click on the form's background or you'll
need a special object that you designed to let the user drag
the form with it's MouseDown/Move events. Be aware that if you
use a special object, the X,Y will be relative to the control -
not the form.
~ JD
|
|
| Back to top |
|
 |
Fishface Guest
|
Posted: Thu Mar 17, 2005 1:59 pm Post subject: Re: Form Dragging??? |
|
|
qyte wrote:
| Quote: | Is there a way to drag a form that it's BorderStyle is bsNone?
|
In the forms OnMouseDown event handler:
ReleaseCapture();
Perform(WM_SYSCOMMAND, 0xF012, 0);
That's the easy way. If you want to do it the hard way, you trap the
WM_NCHITTEST message, call DefWindowProc() with the message,
inspect the result for HTCLIENT and return HTCAPTION instead.
HRESULT lHitTest = DefWindowProc (hwnd, WM_NCHITTEST,
wParam, lParam);
return (lHitTest == HTCLIENT) ? HTCAPTION : lHitTest;
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|