BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Form Dragging???

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
qyte
Guest





PostPosted: Wed Mar 16, 2005 12:11 am    Post subject: Form Dragging??? Reply with quote



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





PostPosted: Wed Mar 16, 2005 9:09 am    Post subject: Re: Form Dragging??? Reply with quote




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





PostPosted: Thu Mar 17, 2005 1:59 pm    Post subject: Re: Form Dragging??? Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.