유돌이

calendar

1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

Notice

2008. 12. 29. 23:41 델파이
MouseMove , MouseDown 이벤트를 이용하여 간단하게 구현할수 있습니다.
아래 코드는 볼랜드포럼에 박지훈.임프님이 올려놓으신 것을 Delphi로 변경한것입니다.
http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=bcb_tip&no=47
그대로 복사해서 쓰셔도 전혀 문제 없을것입니다.
Resizing을 원하시는 Control의 MouseDown , MouseMove이벤트에 아래 코드를 복사해서 넣으셔도 되구요
아니면 Resizing을 원하시는 모든 Control의 이벤트 핸들러를 아래 함수로 연결해 두셔도 됩니다.

const
SC_DRAG_RESIZEL = $f001; // left resize
SC_DRAG_RESIZER = $f002; // right resize
SC_DRAG_RESIZEU = $f003; // upper resize
SC_DRAG_RESIZEUL = $f004; // upper-left resize
SC_DRAG_RESIZEUR = $f005; // upper-right resize
SC_DRAG_RESIZED = $f006; // down resize
SC_DRAG_RESIZEDL = $f007; // down-left resize
SC_DRAG_RESIZEDR = $f008; // down-right resize
SC_DRAG_MOVE = $f012; // move


implementation

{$R *.dfm}

procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
SenderControl: TControl;
begin

SenderControl := TControl(Sender); //dynamic_cast(Sender);
if ((X < 4) AND (Y < 4))or ((X > SenderControl.Width-4) and (Y > SenderControl.Height-4)) then
SenderControl.Cursor := crSizeNWSE
else if ((X < 4) and (Y > SenderControl.Height-4)) or ((X > SenderControl.Width-4) and (Y < 4))then
SenderControl.Cursor := crSizeNESW
else if ((X < 4 )or (X > SenderControl.Width-4))then
SenderControl.Cursor := crSizeWE
else if ((Y < 4) or (Y > SenderControl.Height-4))then
SenderControl.Cursor := crSizeNS
else
SenderControl.Cursor := crDefault;

end;

procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
SenderControl: TWinControl;
SysCommWparam: integer;
begin

SenderControl := TWinControl(Sender);

if (X < 4 )and ( Y < 4) then
SysCommWparam := SC_DRAG_RESIZEUL
else if(X > SenderControl.Width-4) and (Y > SenderControl.Height-4) then
SysCommWparam := SC_DRAG_RESIZEDR
else if(X < 4) and (Y > SenderControl.Height-4) then
SysCommWparam := SC_DRAG_RESIZEDL
else if(X > SenderControl.Width-4 ) and ( Y < 4) then
SysCommWparam := SC_DRAG_RESIZEUR
else if(X < 4) then
SysCommWparam := SC_DRAG_RESIZEL
else if(X > SenderControl.Width-4) then
SysCommWparam := SC_DRAG_RESIZER
else if(Y < 4) then
SysCommWparam := SC_DRAG_RESIZEU
else if(Y > SenderControl.Height-4) then
SysCommWparam := SC_DRAG_RESIZED
else
SysCommWparam := SC_DRAG_MOVE;

ReleaseCapture();
SendMessage(SenderControl.Handle, WM_SYSCOMMAND, SysCommWparam, 0);

end;
posted by 유돌이