我看了一个星期左右的书,差不多也看了4本左右讲类和对象的,还是很混淆
我是初学者,正在学,我们公司的经理为了锻炼偶,出了一个题目给我[自己写一个IMAGE,不准用任何控件,自己在单元里面处理,实现把一幅图移动的效果],图移动我知道算法了,就是~~~~~~自己写一个IMAGE在里面自己实现不知道,看书以后,什么多态啊~~~~~等等还是很头晕,谁在单元里写一个IMAGE,帮我写一个,在麻烦点给我写一下为什么要这样[注释一下],小弟感之不敬,55555555
不知道分够不够,不够在开贴在+
我是初学者,正在学,我们公司的经理为了锻炼偶,出了一个题目给我[自己写一个IMAGE,不准用任何控件,自己在单元里面处理,实现把一幅图移动的效果],图移动我知道算法了,就是~~~~~~自己写一个IMAGE在里面自己实现不知道,看书以后,什么多态啊~~~~~等等还是很头晕,谁在单元里写一个IMAGE,帮我写一个,在麻烦点给我写一下为什么要这样[注释一下],小弟感之不敬,55555555
不知道分够不够,不够在开贴在+
type
a=class(tedit)
end;
procedure 单击事件;
var
ii:a;
begin
ii:=a.Create(self);
ii.Parent:=Form1;
end;就会出现在Form1的上方但是如果这样定义
type
a=class(timage)
end;
他就不会把IMAGE出显在FORM1左上方这样是怎么回事,就是对象和类头大啊~~~~~~~人家说看MSDN好,但是不知道有什么效果!
ii.Parent:=Form1;
ii.Top := 100;
ii.Left := 200; //看看屬性就知道了, 還可設置長寬等到
用VCL写程序,看msdn不十分配套啊,当然,看写什么程序了。
写过1万行以上VCL代码的不会超过5个
简单点说, 至少包括以下过程:
1. 图片格式分析
2. 窗口创建
3. 调用绘图函数显示图片
如果还要求更多的功能 ,将有更大的工作量
晕
unit SmallImage;interfaceuses
Windows, SysUtils, Classes, Controls, Graphics;type
TSmallImage = class(TCustomControl)
private
{ Private declarations }
FPicture: TPicture;
FStretch: Boolean;
procedure SetPicture(const Value: TPicture);
procedure SetStretch(const Value: Boolean);
protected
{ Protected declarations }
procedure Paint; override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property Visible;
property OnClick;
property ShowHint;
property Picture: TPicture read FPicture write SetPicture;
property Stretch: Boolean read FStretch write SetStretch default False;
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('Standard', [TSmallImage]);
end;{ TSmallImage }constructor TSmallImage.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FPicture := TPicture.Create;
Height := 105;
Width := 105;end;destructor TSmallImage.Destroy;
begin
FPicture.Free;
inherited;
end;procedure TSmallImage.Paint;
begin
inherited;
if FStretch then
Canvas.StretchDraw(ClientRect, FPicture.Graphic) //拉伸显示
else
Canvas.Draw(0, 0, FPicture.Graphic); if csDesigning in ComponentState then //是否在设计时
with inherited Canvas do
begin
Pen.Style := psDash;
Brush.Style := bsClear;
Rectangle(0, 0, Width, Height);
end;
end;
procedure TSmallImage.SetPicture(const Value: TPicture);
begin
FPicture.Assign(Value);
end;procedure TSmallImage.SetStretch(const Value: Boolean);
begin
if Value <> FStretch then
begin
FStretch := Value;
Invalidate;
end;
end;end.