打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
写一个可拖动的 TShape

问题来源: http://www.cnblogs.com/del/archive/2009/03/09/1234066.html#1471535

本例效果图:



自定义类(TMyShape)单元 :
unit Unit2;interfaceuses  Classes, Controls, ExtCtrls;type  TMyShape = class(TShape)  private    fMouseFlag: Boolean;    fx,fy: Integer;  protected    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X: Integer;      Y: Integer); override;    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X: Integer;      Y: Integer); override;    procedure MouseMove(Shift: TShiftState; X: Integer; Y: Integer); overrideend;implementation{ TMyShape }procedure TMyShape.MouseDown(Button: TMouseButton; Shift: TShiftState; X,  Y: Integer);begin  inherited;  fx := X;  fy := Y;  fMouseFlag := True;end;procedure TMyShape.MouseMove(Shift: TShiftState; X, Y: Integer);begin  inheritedif fMouseFlag then  begin    Left := Left + X - fx;    Top := Top + Y - fy;  end;end;procedure TMyShape.MouseUp(Button: TMouseButton; Shift: TShiftState; X,  Y: Integer);begin  inherited;  fMouseFlag := False;end;end.

调用测试:
unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls;type  TForm1 = class(TForm)    Button1: TButton;    procedure Button1Click(Sender: TObject);  end;var  Form1: TForm1;implementation{$R *.dfm}uses Unit2;procedure TForm1.Button1Click(Sender: TObject);begin  Randomize;  with TMyShape.Create(Self) do begin    Brush.Color := Random($FFFFFF);    Parent := Self;    Left := 10;    Top := 10end;end;end.
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
delphi在TMemo中实现高亮文字
DELPHI中鼠标的各种操作
Delphi中Frame的使用方法
Delphi中的容器类(转)
Delphi 7学习开发控件(续)
Delphi XE10.1 DataSnap Client Error “SetConnectTimeOut”
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服