网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Delphi
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.对使用Delphi制作DLL复用文件的建.
.如何使用Delphi设计强大的服务器.
.有关TDataSet的研究.
.华为CMPP源码delphi6版.
.具有自动恢复功能的通知栏图标控.
.於Delphi的Case述句中使用字串當.
.Delphi中建议使用的语句.
.Delphi编码规范.
.用Delphi实现风Word97风格的工具.
.如何在程序中使用自己的库单元.
.将某一主机域名解析为IP地址。.
.组件制作之一(概念).
.实现StatusBar的Flat风格.
.序列化FastReport.
.DELPHI下的多线程程序设计(2).
.模拟delphi编辑窗体操作控件。。.
.用Timer实现定时运行.
.DELPHI中图像的显示效果.
.把数据集保存为Excel格式的一个实.
.Delphi的Hint(1).

实现控件的移动、改变大小

发表日期:2006-2-4


实现控件的移动,改变大小(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

上一篇:delphi里播放flash 人气:4301
下一篇:一名Delphi程序员的开发习惯(非技术问题) 人气:4099
浏览全部Delphi的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐