本例效果图:


代码文件:


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls; type
  TMyShape = class(TShape)
  protected
    procedure CMMouseenter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseleave(var Message: TMessage); message CM_MOUSELEAVE;
  end;   TForm1 = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  end; var
  Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);
const
  W = ;
  H = ;
var
  shape: TMyShape;
begin
  shape := TMyShape.Create(Self);
  shape.Parent := Panel1;
  shape.Width := W;
  shape.Height := H;
  Randomize;
  shape.Left := Random(Panel1.ClientWidth - W);
  shape.Top := Random(Panel1.ClientHeight - H);
  shape.Brush.Color := Random($FFFFFF);
end; procedure TForm1.Button2Click(Sender: TObject);
var
  i: Integer;
begin
  if Panel1.ControlCount = then Exit;
  Randomize;
  i := Random(Panel1.ControlCount - );
  Panel1.Controls[i].Free;
end; { TMyShape } procedure TMyShape.CMMouseenter(var Message: TMessage);
const
  s = '当前 %s 的颜色值是: %.6x';
var
  WCtrl: TWinControl;
begin
  WCtrl := Parent;
  while WCtrl.HasParent do WCtrl := WCtrl.Parent;
  if WCtrl is TForm then TForm(WCtrl).Caption := Format(s, [ClassName,Brush.Color]);
  inherited;
end; procedure TMyShape.CMMouseleave(var Message: TMessage);
const
  s = 'Form1';
var
  WCtrl: TWinControl;
begin
  WCtrl := Parent;
  while WCtrl.HasParent do WCtrl := WCtrl.Parent;
  if WCtrl is TForm then TForm(WCtrl).Caption := s;
  inherited;
end; end.

http://www.cnblogs.com/del/archive/2008/10/23/1317926.html

Controls 属性与继承 TShape 类的小练习(使用TShape可以解决很多图形问题)的更多相关文章

  1. python类属性在继承中的修改的影响

    class A(object): x = 1 class B(A): pass class C(A): pass # 通过父类修改类属性,子类继承的类属性也改变 A.x = 3 print(A.x, ...

  2. javascript继承(一)—类的属性研究

    本篇文章主要针对javascript的属性进行分析,由于javascript是一种基于对象的语言,本身没有类的概念,所以对于javascript的类的定义有很多名字,例于原型对象,构造函数等,它们都是 ...

  3. php函数、类和对象以及类的封装、继承、类的静态方法、静态属性

    1.函数     php内置函数可以直接使用,如果没有安装php扩展即可     自定义函数 //函数function 函数名 function dump($var = null){ //支出默认参数 ...

  4. 窥探Swift之类的继承与类的访问权限

    上一篇博客<窥探Swift之别具一格的Struct和Class>的博客可谓是给Swift中的类开了个头.关于类的内容还有很多,今天就来搞一下类中的继承以及类的访问权限.说到类的继承,接触过 ...

  5. C++继承 派生类中的内存布局(单继承、多继承、虚拟继承)

    今天在网上看到了一篇写得非常好的文章,是有关c++类继承内存布局的.看了之后获益良多,现在转在我自己的博客里面,作为以后复习之用. ——谈VC++对象模型(美)简.格雷程化    译 译者前言 一个C ...

  6. Swift 之类的继承与类的访问权限

    http://www.cocoachina.com/swift/20160104/14821.html 上一篇博客<窥探Swift之别具一格的Struct和Class>的博客可谓是给Swi ...

  7. 关于对象的行为、数组、继承和类的高级概念(Java)

    1.对象的行为:                   (1)方法调用栈:所有的方法调用都维护在一个称为调用栈的结构中. 第一个被调用的方法就是main(),该方法是Jvm调用的,因此main()方法总 ...

  8. 【CSS简介、基础选择器、字体属性、文本属性、引入方式】前端小抄(2) - Pink老师自学笔记

    [CSS简介.基础选择器.字体属性.文本属性.引入方式]前端小抄(2) 本学习笔记是个人对 Pink 老师课程的总结归纳,转载请注明出处! 一.CSS简介 CSS 的主要使用场景就是布局网页,美化页面 ...

  9. JSON生成c#类代码小工具

    JSON生成c#类代码小工具 为什么写这么个玩意 最近的项目中需要和一个服务端程序通讯,而通讯的协议是基于流行的json,由于是.net,所以很简单的从公司代码库里找到了Newtonsoft.dll( ...

随机推荐

  1. Asp.net压缩网站中的文件

    为了说明自定义虚拟路径,这里弄个示例,仅仅用一个压缩包存放一个网站的多个文件. 这个东西是要需要通过实现3个抽象类来实现: System.Web.Hosting.VirtualPathProvider ...

  2. 【25.23%】【codeforces 731C】Socks

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. ServletContextListener接口用法

    ServletContextListener接口用于tomcat启动时自动加载函数,方法如下: 一.需加载的类必须实现ServletContextListener接口. 二.该接口中有两个方法必须实现 ...

  4. Android SDK location should not contain whitespace, as this cause problems with NDK tools

    解决方案一: The easiest solution is to move the SDK somewhere else, where there is no space or other whit ...

  5. Managing uniquely tagged items using the internet

    The invention teaches managing an item in the Internet of Things, wherein the system comprises: an i ...

  6. dwc_otg驱动 "BUG: sleeping function called from invalid context at mm/page_alloc.c"

    方案商的开发板上otg功能只能做device,硬件看过后说没有5v供电,加上后能够识别U盘了,但是内核报了错 [ 3.264000] usb 2-1: new high-speed USB devic ...

  7. Redis入门手册

    这篇文章主要介绍了超强.超详细Redis入门教程,本文详细介绍了Redis数据库各个方面的知识,需要的朋友可以参考下 [本教程目录] 1.redis是什么 2.redis的作者何许人也 3.谁在使用r ...

  8. repo/git Android/CyanogenMod srouce code

    For getting the whole Android/CM rom source code, 1. get the repo first.2. make sure the git is inst ...

  9. 创Python规划2

    于Milang的IDE多年的编辑后,,然后按F5关于实施.这将是在下面Output输出形式"Hello, World!"弦,例如下面的附图: watermark/2/text/aH ...

  10. 利用tcpdump抓包工具监控TCP连接的三次握手和断开连接的四次挥手

    TCP传输控制协议是面向连接的可靠的传输层协议,在进行数据传输之前,需要在传输数据的两端(客户端和服务器端)创建一个连接,这个连接由一对插口地址唯一标识,即是在IP报文首部的源IP地址.目的IP地址, ...