| View previous topic :: View next topic |
| Author |
Message |
qyte Guest
|
Posted: Tue Mar 15, 2005 2:23 pm Post subject: Forms Docking to Desktop edges? |
|
|
Does anyone know what can i do so that a form can attach to the desktop
edges when dragging it?
I don't know anything on the matter.
a good description would be great.
|
|
| Back to top |
|
 |
Dirk Schnitzler Guest
|
Posted: Thu Mar 24, 2005 4:20 pm Post subject: Re: Forms Docking to Desktop edges? |
|
|
"qyte" <gyte (AT) vivodinet (DOT) gr> schrieb im Newsbeitrag
news:4236efc4 (AT) newsgroups (DOT) borland.com...
| Quote: | Does anyone know what can i do so that a form can attach to the desktop
edges when dragging it?
I don't know anything on the matter.
a good description would be great.
|
My code should be very easy to follow...
Sample header file:
class TfrmMain : public TForm
{
__published:
private:
public:
__fastcall TfrmMain(TComponent* Owner);
bool AllowOutside;
void __fastcall OnFormMove(TWMMove aMsg);
protected:
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(WM_MOVE, TWMMove, OnFormMove)
END_MESSAGE_MAP(TForm)
};
Sample cpp file:
file://---------------------------------------------------------------------
------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
: TForm(Owner)
{
AllowOutside = false;
}
file://---------------------------------------------------------------------
------
void __fastcall TfrmMain::OnFormMove(TWMMove aMsg)
{
static int OldLeft = Left;
static int OldTop = Top;
if(OldLeft!=Left || OldTop!=Top){
file://Form has been moved... check distance to screen borders:
int Right = Left + Width;
int Bottom = Top + Height;
int BottomBorder = Screen->WorkAreaTop+Screen->WorkAreaHeight;
int RightBorder = Screen->WorkAreaLeft+Screen->WorkAreaWidth;
if(Left>0 || !AllowOutside){
if(Screen->WorkAreaLeft+SNAP_DIF_X >= Left){
Left = Screen->WorkAreaLeft;
}
}
if(Right<RightBorder || !AllowOutside){
if(Right >= RightBorder-SNAP_DIF_X){
Left = RightBorder-Width;
}
}
if(Top>0 || !AllowOutside){
if(Screen->WorkAreaTop+SNAP_DIF_X >= Top){
Top = Screen->WorkAreaTop;
}
}
if(Bottom<BottomBorder || !AllowOutside){
if(Bottom >= BottomBorder-SNAP_DIF_Y){
Top = BottomBorder-Height;
}
}
}
OldLeft = Left;
OldTop = Top;
}
Regards,
Dirk.
|
|
| Back to top |
|
 |
Dirk Schnitzler Guest
|
Posted: Thu Mar 24, 2005 4:30 pm Post subject: Re: Forms Docking to Desktop edges? |
|
|
Ok, since the OnMove event isnīt fired when you move
around the form and put it back on itīs original position,
you can save the static variables...
void __fastcall TfrmMain::OnFormMove(TWMMove aMsg)
{
int Right = Left + Width;
int Bottom = Top + Height;
int BottomBorder = Screen->WorkAreaTop+Screen->WorkAreaHeight;
int RightBorder = Screen->WorkAreaLeft+Screen->WorkAreaWidth;
if(Left>0 || !AllowOutside){
if(Screen->WorkAreaLeft+SNAP_DIF_X >= Left)
Left = Screen->WorkAreaLeft;
}
if(Right<RightBorder || !AllowOutside){
if(Right >= RightBorder-SNAP_DIF_X)
Left = RightBorder-Width;
}
if(Top>0 || !AllowOutside){
if(Screen->WorkAreaTop+SNAP_DIF_X >= Top)
Top = Screen->WorkAreaTop;
}
if(Bottom<BottomBorder || !AllowOutside){
if(Bottom >= BottomBorder-SNAP_DIF_Y)
Top = BottomBorder-Height;
}
}
|
|
| Back to top |
|
 |
Dirk Schnitzler Guest
|
Posted: Thu Mar 24, 2005 4:33 pm Post subject: Re: Forms Docking to Desktop edges? |
|
|
I hope this is the last time ....
Change it to:
if(Top>0 || !AllowOutside){
if(Screen->WorkAreaTop+SNAP_DIF_Y >= Top)
Top = Screen->WorkAreaTop;
}
Instead of:
| Quote: | if(Top>0 || !AllowOutside){
if(Screen->WorkAreaTop+SNAP_DIF_X >= Top)
Top = Screen->WorkAreaTop;
}
|
Regards,
Dirk.
|
|
| Back to top |
|
 |
|