¾î¸°¿ÕÀÚ ´ÔÀÌ ¿Ã¸°°ÍÀ» Á¶±Ý ¼öÁ¤ÇÏ¿´½À´Ï´Ù.
private
{ Private declarations }
public
{ Public declarations }
procedure MouseControl(x,y:Integer);
end;
var
Form1: TForm1;
Mouse_Down_Bool : Boolean;
startX, startY : integer;
fDragging : Boolean;
fRect : TRect;
implementation
{$R *.DFM}
procedure TForm1.Panel_BackMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
i:integer;
begin
// PaintBox1.Enabled := False ¶Ç´Â PaintBox1.Visible := False ·Î Çؾ߸¸ ±×·ÁÁü.
if shift = [ssctrl,ssleft] then
begin
// ÷ µå·¡±×(Ctrl+left)½ÃÀÛÇϱâÀü¿¡ ÃʱâÈ
fDragging := true; //Àü¿¡ µå·¡±×Ç÷¡±×º¯¼ö(Private) Á¤ÀÇÇÔ.
fRect.Left := 0;
fRect.Right := 0;
fRect.Top := 0;
fRect.Bottom := 0;
PaintBox1.Canvas.DrawFocusRect(fRect);
// ½ÃÀÛÀ§Ä¡±â¾ïÇÏ´Â º¯¼ö(Private)
StartX := X;
StartY := Y;
end;
end;
procedure TForm1.Panel_BackMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
if fDragging then
begin
With PaintBox1 do // ÆäÀÎÆ®¹Ú½º¿¡ »ç°¢Çü ¿µ¿ªÀ» ±×¸²
begin
Canvas.DrawFocusRect(fRect); // ÀÌÀüÀÇ »ç°¢ÇüÀ» Áö¿ì°í
fRect.Left:= Min(StartX,x);
fRect.Right:= Max(StartX,x);
fRect.Top:= Min(StartY,y);
fRect.Bottom:= Max(StartY,y);
Canvas.DrawFocusRect(fRect); // ´Ù½Ã ¿µ¿ªÀ¸·Î »ç°¢ÇüÀ» ±×¸®°í
end;
end;
end;
procedure TForm1.Panel_BackMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
i, WidthNum, HeightNum : integer;
PnlSender : TPanel absolute Sender;
TmpPanel:TPanel;
begin
if fDragging then
begin
for i := 0 to PnlSender.ControlCount - 1 do
begin
// ÄÁÆ®·ÑÀÌ TPanelÀΰ¡?
if (PnlSender.controls[i] is TPanel) then
begin
// °¢°¢ÀÇ PanelÀ» Àоî¼
TmpPanel:= TPanel(PnlSender.controls[i]);
WidthNum := Max(abs(TmpPanel.left + TmpPanel.width - fRect.Left),
abs(TmpPanel.left - fRect.Right));
// ¿µ¿ª»ç°¢ÇüÀÇ °¡·Îº¯°ú ÆгÎÀÇ °¡·Îº¯ÀÇ °¡Àå¸Õ°Å¸®¸¦ ±¸ÇÑ´Ù.
HeightNum := Max(abs(TmpPanel.Top + TmpPanel.Height-fRect.Top),
Abs(TmpPanel.Top - fRect.Bottom));
// ¿µ¿ª»ç°¢ÇüÀÇ ¼¼·Îº¯°ú ÆгÎÀÇ »õ·Îº¯ÀÇ °¡Àå¸Õ°Å¸®¸¦ ±¸ÇÑ´Ù.
// ¸¸ÀÏ ÀÌ·¸°Ô ±¸ÇÑ °¢°¢ÀÇ °Å¸®°¡, ¿µ¿ª»ç°¢Çü,ÆгÎÀÇ °¡·ÎÇÕ,¼¼·ÎÇÕº¸´Ù Å©¸é °ãÄ£´Ù.( ÇÑÁ÷¼±»óÀÇ µÎ°³ÀÇ ¼±ºÐÀÌ °ãÄ¥Á¶°Ç..)
if (WidthNum <= ((fRect.Right - fRect.left) + (TmpPanel.width))) and
(HeightNum <= ((fRect.Bottom - fRect.Top) + (TmpPanel.Height))) then
begin
{ if TmpPanel.BorderWidth = 3 then
TmpPanel.BorderWidth := 0
else }
TmpPanel.BorderWidth := 3;
end;
end;
end; // for
MouseControl(x,y);
fDragging := false; // µå·¡±×Ç÷¡±×¸¦ false½ÃÅ°°í
PaintBox1.Canvas.DrawFocusRect(fRect); // ¿µ¿ª »ç°¢ÇüÀ» Áö¿ì°í
invalidate; // ´Ù½Ã ±×·ÁÁÜ.
ClipCursor(nil); //¸¶¿ì½º ¸ø¿òÁ÷ÀÌ´Â ¿µ¿ªÀ» ÇØü
end;
end;
// µå·¡±×¸ðµå¿¡¼ ¸¶¿ì½º°¡ Panel_Back ¹Ú½º³» ¿¡¸¸ ¿òÁ÷ÀÌ°Ô ÇÏ´Â ÄÚµå
procedure TForm1.MouseControl(x,y:Integer);
var
xbar, ybar : integer; // ½ºÅ©·Ñ¹ÙÀÇ ³ÐÀÌ º¯¼ö
PanelRect : TRect; // ½ºÅ©·Ñ¹Ú½ºÀÇ ¿µ¿ª
begin
xbar:=0;
ybar:=0;
PanelRect.TopLeft := Panel_Back.ClientToScreen(
Point(Panel_Back.left, Panel_Back.top + Panel_Back.top));
PanelRect.Right := PanelRect.TopLeft.x + Panel_Back.Width;
//½ºÅ©·Ñ¹Ú½º ¾Æ·¡ÂÊ ¹üÀ§±îÁö ¸ø¿òÁ÷°Ô ÇÔ.
PanelRect.bottom := PanelRect.TopLeft.y + Panel_Back.Height;
InflateRect(PanelRect, 0,0); //API ÇÔ¼ö
ClipCursor(@PanelRect); //Ä¿¼¸¦ Á¤ÇÑ ¹üÀ§¿¡ ¸ø ¿òÁ÷ÀÌ°Ô ÇÔ.
end;