bit := TBitmap.Create;
bit.LoadFromFile('d:\vcl\aa.bmp');
StretchBlt(Canvas.Handle,0,0,100,100,bit.Canvas.Handle,0,0,bit.Width,bit.Height,SRCCOPY );
unit Myhead;
interface
uses
Windows, SysUtils, Classes, Controls, Graphics, jpeg;
type
TMyhead = class(TCustomControl)
private
{ Private declarations }
FIsOn: Boolean;
FPicOn: TJPEGImage;
FPicOff: TJPEGImage;
procedure SetIsOn(const Value: Boolean);
protected
{ Protected declarations }
procedure Paint;override;
procedure Click;override;
public
{ Public declarations }
constructor Create(A: TComponent);override;
destructor Destroy;override;
published
{ Published declarations }
property IsOn: Boolean read FIsOn write SetIsOn;
property Width;
property Height;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TMyhead]);
end;
{ TMyhead }
procedure TMyhead.Click;
begin
IsOn := not FIsOn;
inherited;
end;
constructor TMyhead.Create(A: TComponent);
begin
inherited Create(A);
FPicOn := TJPEGImage.Create;
FPicOn.LoadFromFile('d:\vcl\aa.jpg');
FPicOff := TJPEGImage.Create;
FPicOff.LoadFromFile('d:\vcl\b.jpg');
end;
destructor TMyhead.Destroy;
begin
FPicOn.Free;
FPicOff.Free;
inherited Destroy;
end;
procedure TMyhead.Paint;
begin
inherited;
if FIsOn then
begin
Canvas.StretchDraw(Rect(0,0,Width,Height), FPicOn);
end
else
begin
Canvas.StretchDraw(Rect(0,0,Width,Height), FPicOff);
end;
end;
procedure TMyhead.SetIsOn(const Value: Boolean);
begin
FIsOn := Value;
Invalidate;
end;
end.
Delphi控件开发(四)双击头像切换
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- Xamarin XAML语言教程构建ControlTemplate控件模板 控件模板ControlTemplate...
- 从小哥哥那里学到的一个控件,赶紧记录下来。。。啦啦啦~ 先上个效果图 没错,排版就是这么粗糙。。毕竟是周末加班系列...
- 注:本文部分知识点参考了郭霖的《第一行代码》(第二版) 一、简单了解控件和布局的继承结构 我们所有的控件都是直接或...
- 哎呀呀,,最近怎么搞?!!感觉学习进度实在太慢了,但是熬夜通宵宝宝实在是做不到啊!!!不知道大神们通宵码代码,第二...
- 今天来讲一讲iOS实际开发中,对于头像的应用。 现在的APP中,对于头像的设置,我们大多采用圆形头像,并且需要支持...