實現控件的移動,改變大小(DELPHI實現)

實現控件的移動,改變大小(DELPHI實現)

主要使用Perform方法
  function Perform(Msg: Cardinal; WParam, LParam: Longint): Longint;
 
只要能夠使用類似於win32API的函數SendMessage(),本方法同樣可在其他環境裏應用。

用Delphi實現
首先,建立一個應用程序,在一個窗體里加入一個Panel1,保存爲main.pas;
然後,分別在Panel1的鼠標移動、鼠標按下事件裏添加代碼;
鼠標移動:控制光標的形狀
procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if (x>=0)and(x<=3) then
  begin
    if (y>=0)and(y<=3) then Panel1.Cursor:=crSizeNWSE;
    if (y>3)and(y<Panel1.Height-3) then Panel1.Cursor:=crSizeWE;
    if (y>=Panel1.Height-3)and(y<=Panel1.Height) then Panel1.Cursor:=crSizeNESW;
  end
  else if (x>3)and(x<Panel1.Width-3) then
  begin
    if (y>=0)and(y<=3) then Panel1.Cursor:=crSizeNS;
    if (y>3)and(y<Panel1.Height-3) then Panel1.Cursor:=crArrow;
    if (y>=Panel1.Height-3)and(y<=Panel1.Width) then Panel1.Cursor:=crSizeNS;
  end
  else if (x>=Panel1.Width-3)and(x<=Panel1.Width) then
  begin
    if (y>=0)and(y<=3) then Panel1.Cursor:=crSizeNESW;
    if (y>3)and(y<Panel1.Height-3) then Panel1.Cursor:=crSizeWE;
    if (y>=Panel1.Height-3)and(y<=Panel1.Width) then Panel1.Cursor:=crSizeNWSE;
  end;
end;

鼠標按下:控制Panel的大小或位置
procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  if (x>=0)and(x<=3) then
  begin
    file://左上角方向改變大小
    if (y>=0)and(y<=3) then Panel1.Perform(WM_SysCommand,$F004,0);
    file://左側
    if (y>3)and(y<Panel1.Height-3) then Panel1.Perform(WM_SysCommand,$F001,0);
    file://左下角
    if (y>=Panel1.Height-3)and(y<=Panel1.Height) then Panel1.Perform(WM_SysCommand,$F007,0);
  end
  else if (x>3)and(x<Panel1.Width-3) then
  begin
    file://上側
    if (y>=0)and(y<=3) then Panel1.Perform(WM_SysCommand,$F003,0);
    file://移動控件
    if (y>3)and(y<Panel1.Height-3) then Panel1.Perform(WM_SysCommand,$F012,0);
    file://下側
    if (y>=Panel1.Height-3)and(y<=Panel1.Width) then Panel1.Perform(WM_SysCommand,$F006,0);
  end
  else if (x>=Panel1.Width-3)and(x<=Panel1.Width) then
  begin
    file://右上角
    if (y>=0)and(y<=3) then Panel1.Perform(WM_SysCommand,$F005,0);
    file://右側
    if (y>3)and(y<Panel1.Height-3) then Panel1.Perform(WM_SysCommand,$F002,0);
    file://右下角
    if (y>=Panel1.Height-3)and(y<=Panel1.Width) then Panel1.Perform(WM_SysCommand,$F008,0);
  end;
end;
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章