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


本例效果图:


自定义类(TMyShape)单元 :


unit Unit2;

interface

uses
  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); override;
  end; 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
  inherited;
  if 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;

interface

uses
  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 := ;
    Top := ;
  end;
end; end.

http://www.cnblogs.com/del/archive/2009/03/09/1406811.html

最新文章

  1. WPF 后台读取样式文件
  2. jquery属性
  3. 每瓶啤酒2元,2个空酒瓶或4个瓶盖可换1瓶啤酒。10元最多可喝多少瓶啤酒? php
  4. 立体透视 perspective transform-style 倾斜旋转
  5. 李洪强iOS开发之-Swift_00_介绍
  6. 如用使用高版本framework,比如支持iOS5及以上的工程中使用Social.framework
  7. cpuimage 开源之
  8. Java获取当前的年月
  9. 使用JavaScript动态的添加组件
  10. Python-定时爬取指定城市天气(二)-邮件提醒
  11. es6写法
  12. mysql中注释的添加修改
  13. vmware提示请卸载干净再重新安装的解决办法
  14. stl string的erase方法
  15. Python之DataFrame常用方法小结
  16. <转>聊聊持续集成
  17. Linux上vi编辑文件非正常退出后文件恢复
  18. How To Pronounce 3-Syllable Phrases
  19. ng2-file-upload 使用记录
  20. centos7设置SSH安全策略–指定IP登陆

热门文章

  1. 【44.19%】【codeforces 608D】Zuma
  2. spring boot jar包 linux 部署
  3. Cordova各种事件
  4. jQuery在线选座订座(高铁版)
  5. 10g RAC 采用service达到taf
  6. Android官方教程翻译(5)——设置ActionBar
  7. (记录)mysql分页查询,参数化过程的坑
  8. JSON的一些要点总结 专题
  9. EasyUI-DataGrid多线动态实现选择性合并
  10. Android Intent传递对象摘要