国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

實現控件的移動、改變大小

2019-11-18 18:46:30
字體:
來源:轉載
供稿:網友

實現控件的移動,改變大小(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;
主要使用 Perform 方法為

附錄1.全部代碼如下:

unit main;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  if (x>=0)and(x<=3) then
  begin
    if (y>=0)and(y<=3) then Panel1.Perform(WM_SysCommand,$F004,0);
    if (y>3)and(y<Panel1.Height-3) then Panel1.Perform(WM_SysCommand,$F001,0);
    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
    if (y>=0)and(y<=3) then Panel1.Perform(WM_SysCommand,$F003,0);
    if (y>3)and(y<Panel1.Height-3) then Panel1.Perform(WM_SysCommand,$F012,0);
    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
    if (y>=0)and(y<=3) then Panel1.Perform(WM_SysCommand,$F005,0);
    if (y>3)and(y<Panel1.Height-3) then Panel1.Perform(WM_SysCommand,$F002,0);
    if (y>=Panel1.Height-3)and(y<=Panel1.Width) then Panel1.Perform(WM_SysCommand,$F008,0);
  end;
end;

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;

附錄2.API SendMessage()介紹
SendMessage === user32.lib
LRESULT SendMessage(

    HWND hWnd, // handle of destination window
    UINT Msg, // message to send
    WPARAM wParam, // first message parameter
    LPARAM lParam  // second message parameter
   );

 

             2001.9.27


上一篇:再談多態--多態的應用舉例:

下一篇:淺談多態――概念描述

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
學習交流
熱門圖片

新聞熱點

疑難解答

圖片精選

網友關注

主站蜘蛛池模板: 巴林左旗| 大洼县| 呼图壁县| 林芝县| 苍梧县| 宁河县| 江阴市| 凤台县| 都兰县| 凤山市| 汉源县| 建昌县| 罗江县| 兰考县| 肥西县| 玛纳斯县| 邹平县| 常州市| 绥阳县| 徐水县| 息烽县| 西丰县| 罗源县| 苍溪县| 韩城市| 清远市| 独山县| 富蕴县| 呼伦贝尔市| 肇庆市| 富民县| 盱眙县| 灵石县| 永定县| 弥勒县| 朝阳区| 修水县| 武夷山市| 邹平县| 太仆寺旗| 康平县|