码迷,mamicode.com
首页 > Windows程序 > 详细

MyWinControl不能作为设计期间的容器

时间:2014-08-23 21:31:11      阅读:267      评论:0      收藏:0      [点我收藏+]

标签:des   color   io   for   ar   代码   amp   line   sp   

unit MyWinControl;

interface

uses
SysUtils, Classes, Controls, Windows;

type
TMyWinControl = class(TWinControl)
protected
procedure PaintWindow(DC: HDC); override;
public
constructor Create(AOwner: TComponent); override;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents(‘Samples‘, [TMyWinControl]);
end;

constructor TMyWinControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlState := ControlState + [csCustomPaint];
// 必须通知 WMPaint 需要画自己
end;

procedure TMyWinControl.PaintWindow(DC: HDC);
var
Rect: TRect;
begin
Windows.GetClientRect(Handle, Rect);
FillRect(DC, Rect, COLOR_BTNSHADOW + 1);
SetBkMode(DC, TRANSPARENT);
DrawText(DC, ‘Hello, TMyWinControl‘, -1, Rect, DT_SINGLELINE or DT_VCENTER or DT_CENTER);
end;

end.

------------------------------------------------------------------------------------------------

但代码指定则可以,而且还能跟随父控件一起销毁:

procedure TForm1.Button1Click(Sender: TObject);
begin
button2.Parent:=MyWinControl1;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
MyWinControl1.Destroy;
end;

 

MyWinControl不能作为设计期间的容器

标签:des   color   io   for   ar   代码   amp   line   sp   

原文地址:http://www.cnblogs.com/findumars/p/3931703.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!