type
TBorderPos = (bpTopLeft, bpTopRight, bpBottomLeft,
bpBottomRight, bpTop, bpBottom,bpLeft,bpRight,bpnone);
vsForm: TBGRAVirtualScreen;
.
.
implementation
uses
uResize;
.
.
procedure TForm1.FormCreate(Sender: TObject);
begin
BorderStyle := bsNone;
{$ifdef Windows}
// DropShadow(Handle); // Better to use SetClasslong() as follows (Windows OS only):
{Handle = all Forms, frmMain.Handle = only frmMain Form
SetClassLong(Handle, GCL_STYLE, GetClassLong(Handle, GCL_STYLE) or CS_DROPSHADOW);
}
SetClassLong(Form1.Handle, GCL_STYLE, GetClassLong(Form1.Handle, GCL_STYLE) or CS_DROPSHADOW);
SetWindowPos(Handle, HWND_TOP, Left, Top, Width, Height, SWP_FRAMECHANGED);
{$else}
// Something to be done for OS <> Windows?
{$endif}
DoubleBuffered := True;
end;
.
.
procedure TForm1.vsFormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
MouseCapture := True;
end;
procedure TForm1.vsFormMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
var LeftEdge,RightEdge,TopEdge,BottomEdge: Boolean;
BorderPosition: TBorderPos;
BW: Integer;
begin
BW := 8;
LeftEdge := False;
RightEdge := False;
TopEdge := False;
BottomEdge := False;
//Check if mouse cursor is on left or right edge
if X < BW then
begin
LeftEdge := True;
end
else if X > vsForm.Width-BW then
begin
RightEdge := True;
end;
//Check if mouse cursor is on top or bottom edge
if Y < BW then
begin
TopEdge := True;
end
else if Y > vsForm.Height-BW then
begin
BottomEdge := True;
end;
//Get border position by using if..else if..else clause in order for if block
//to break as soon as one of the conditions is met
//First check for corners
if TopEdge and LeftEdge then BorderPosition := bpTopLeft
else if TopEdge and RightEdge then BorderPosition := bpTopRight
else if BottomEdge and LeftEdge then BorderPosition := bpBottomLeft
else if BottomEdge and RightEdge then BorderPosition := bpBottomRight
//and only then check for individual edges
else if TopEdge then BorderPosition := bpTop
else if BottomEdge then BorderPosition := bpBottom
else if LeftEdge then BorderPosition := bpLeft
else if RightEdge then BorderPosition := bpRight
//mouse cursor is not on any border edge
else BorderPosition := bpNone;
//Finally you can use case statement to execute needed code based on which
//border edge is your mouse cursor positioned
case BorderPosition of
bpNone:
begin
Label1.Caption := 'Not on border';
vsForm.Cursor:=crDefault;
end;
bpLeft:
begin
Label1.Caption := 'Left border';
vsForm.Cursor:=crSizeWE;
if ssLeft in shift then
ResizeForm.SetMouseDown( self, 5 );
end;
bpRight:
begin
Label1.Caption := 'Right border';
vsForm.Cursor := crSizeWE;
if ssLeft in Shift then
ResizeForm.SetMouseDown( self, 4 );
end;
bpTop:
begin
Label1.Caption := 'Top border';
vsBottom.Cursor := crSizeNS;
if ssLeft in Shift then
ResizeForm.SetMouseDown( self, 10 );
end;
bpBottom:
begin
Label1.Caption := 'Bottom border';
vsForm.Cursor :=crSizeNS;
if ssLeft in Shift then
ResizeForm.SetMouseDown( self, 8 );
end;
bpTopLeft:
begin
Label1.Caption := 'Top Left corner';
vsForm.Cursor :=crSizeNWSE;
if ssLeft in Shift then
ResizeForm.SetMouseDown( self, 15 );
end;
bpTopRight:
begin
Label1.Caption := 'Top Right corner';
vsForm.Cursor :=crSizeNESW;
if ssLeft in Shift then
ResizeForm.SetMouseDown( self, 14 );
end;
bpBottomLeft:
begin
Label1.Caption := 'Bottom Left corner';
vsForm.Cursor :=crSizeNESW;
if ssLeft in Shift then
ResizeForm.SetMouseDown( self, 13 );
end;
bpBottomRight:
begin
Label1.Caption := 'Bottom Right corner';
vsForm.Cursor :=crSizeNWSE;
if ssLeft in Shift then
ResizeForm.SetMouseDown( self, 12 );
end;
end;
end;