我的空件为什么显示不出来(100分)

T

TOTO

Unregistered / Unconfirmed
GUEST, unregistred user!
type
TBlockList = class(TGraphicControl)
private
Data : array[1..20] of Byte;
ItemWidth, ItemHeight : Integer;

fPicture : TPicture;

procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
procedure WMMouseMove (var Msg : TWMMouseMove); message WM_MOUSEMOVE;
procedure WMEraseBkgnd (var Msg : TWMEraseBkgnd ); message WM_EraseBkgnd;
procedure DrawBox;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Paint; override;
published
property Canvas;
property Hint;
property ShowHint;
property Pictuer : TPicture read fPicture ;
property Visible;
property OnClick;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
end;

procedure Register;

{$R BlockTitle.Res}

implementation

constructor TBlockList.Create(AOwner: TComponent);
var
I : Integer;
begin
inherited Create(AOwner);
ControlStyle := ControlStyle + [csFixedWidth , csFixedHeight, csOpaque ];

Parent := TWinControl(AOWner);
fPicture := TPicture.Create;
fPicture.Bitmap.Handle := LoadBitmap(hInstance, 'DEFAULT');
ItemHeight := fPicture.Height div 4;
ItemWidth := fPicture.Width;

ShowHint := TRUE;
for i := 1 to 20 do
Data := 0;
DrawBox;

end;

destructor TBlockList.Destroy;
begin
fPicture.Free;
inherited Destroy;
end;

procedure TBlockList.WMPaint(var Message: TWMPaint);
begin//here
inherited;
end;

procedure TBlockList.DrawBox;
var
i : Integer;
begin
for i:= 1 to 20 do
begin
with Canvas do
begin
case Data of
0 : Bitblt( Handle, ( i - 1 ) * ItemWidth, 0, ItemWidth, ItemHeight,
fPicture.Bitmap.Canvas.Handle, 0, ItemHeight * 3, SRCCOPY );
1, 2 : Bitblt( Handle, ( i - 1 ) * ItemWidth, 0, ItemWidth, ItemHeight,
fPicture.Bitmap.Canvas.Handle, 0, ItemHeight * 2, SRCCOPY );
3, 4, 5 : Bitblt( Handle, ( i - 1 ) * ItemWidth, 0, ItemWidth, ItemHeight,
fPicture.Bitmap.Canvas.Handle, 0, ItemHeight , SRCCOPY );
end;
end;
end;
end;

procedure TBlockList.Clear;
var
I : Integer;
begin
for i := 1 to 20 do
Data := 0;
DrawBox;
end;

procedure TBlockList.Paint;
begin
inherited Paint;
DrawBox;
end;


procedure TBlockList.WMMouseMove(var Msg : TWMMouseMove);
var
x, p : Integer;
begin
x := Msg.XPos;
if (x mod ItemWidth) = 0 then
p := x div ItemWidth
else
P := ( X div ItemWidth ) + 1;
Hint := Format('分数: d% ', [P]);
inherited;
end;

procedure TBlockList.WMEraseBkgnd (var Msg : TWMEraseBkgnd );
begin
Msg.Result := 1;
end;

end.

请教打下:
这是原代码。我为了调试, 在另一个FORM动态创建了一个空间。
并在FORM上显示。我跟踪Create 正常,但却没有显示出来。我有假手
WM_Paint消息中显示调用PAINT并在PAINT中设段点, 可根本没有中断。
增么回师?

另外, 那为打下能把DELPHI创建一个空间的过程叙述以下。
那一个函数进行了那些操作, 分别有什么用。

请打下费心,分数不够我另加!!
 
控件好像问题不大,估计是你的动态创建语句有问题.
应为:
myBlockList := TBlockList.create(form1);
myBlockList.Parent := form1; //must add this line;
然后给上下左右赋值,否则恐怕会在左上角显示.
 
你的控件没有给它的大小赋初值,建议在create中加上,如width:=40;Height:=80,
或SetBounds(0,0,40,80),就没问题了.
 
Why don't you inherit a TImage and put the DrawBox in it?
 
可视控件一般都有WIDTH 和 HEIGHT 属性的:
但继承自可视控件你就不必设置了,当然你也可以重新设置:
property WIDTH :integer read .. write .. default 64
property HEIGHT :integer read .. write .. default 48

另外,CREATE 后,要把控件显示出来,必须设置它的 Parent 为一个可视控件
.
.
应该没有别的问题了,我就是这么用的,你也不该再有问题了 :)
 
> Parent := TWinControl(AOWner);
在Create 中不是副职了吗? 动态创建时还要副职吗?

>我有在WM_Paint消息中显式调用PAINT并在PAINT中设段点, 可根本没有中断。
>增么回师??????????????
> 另外, 那为打下能把DELPHI创建一个空间的过程叙述以下。那一个函数进
>行了那些操作, 分别有什么用。
> 请打下费心,分数不够我另加!!!!!!!!!!!!!!
 
不知到你试过给它的大小赋初值了吗?我试过可以了啊,但由于没你的资源文件,
没法调试,但paint消息响应了啊,由于TGraphicControl及其基类没给width
和height赋值,所以其缺省值都为0,怎么会显示出来呢?
 
Hi TOTO:

你的控件缺少两样东西:
1. 在Create中没有默认大小或者FPicture.LoadBitmap后应该调整控件大小
2. 在画各自效果是循环中要使用Delay, 否则太快无动画效果
此外有一个错误
Hint := Format('分数: d%', [P]); -> Hint := Format('分数: %d', [P]);
Hint 需要 Update

 
>>此外有一个错误 Hint := Format('分数: d%', [P]); -> Hint := Format('分数: %d', [P]);
>> Hint 需要 Update

??? 没理解, 错在哪? 什么叫hint需要Update???
 
To Another_eYe:

1. Format中 d% 错误, 应该为 %d.
2. 根据作者的原意, Mouse Move 到控件的不同区域应该能够显示不同的分数, 但是
HintWindow 只是在 Mouse 进入控件区域时显示一次, 必须刷新 HintWindow才
能达到预想效果
 
对:
>我有在WM_Paint消息中显式调用PAINT并在PAINT中设段点, 可根本没有中断。
的看法:
如果没有 可视的 Parent ,也就是说它根本没有显示出来,你认为它会执行到
断点吗?
 
Hi TOTO:

我画出来的东西不知道有什么意义?

自左向右画20次, 每次取原图高度的1/4(根据data数组的数值)宽度不变的一条.
每次鼠标移动到相应的块上, 显示"分数: n of 20".

constructor TBlockList.Create(AOwner: TComponent);
var
I : Integer;
begin
inherited Create(AOwner);
//ControlStyle := ControlStyle + [csFixedWidth , csFixedHeight, csOpaque ];
Parent := TWinControl(AOWner);
fPicture := TPicture.Create;
//fPicture.Bitmap.Handle := LoadBitmap(hInstance, DEFAULT');
fPicture.Bitmap := Image1.Picture.Bitmap;
ItemWidth := fPicture.Width; //or Parent.ClientWidth div 20;
ItemHeight := fPicture.Height div 4;
width:=ItemWidth * 20; //or Parent.ClientWidth;
height:=ItemHeight;
ShowHint := TRUE;
for i := 1 to 20 do
Data := Random(5);
//DrawBox;
end;
 
各位的建议都对, 我在动态创建时错了

t := TBlockList.Create;
t.Parent := Self;//少了这句.
t.Left ;= 0;
t.Top := 0;
另外, 控件中没有定义边界.
这次分数平均分配.
不过,我还不明百:
在控件中
Parent := TWinControl(AOWner);
还必须在动态创建时给Parent 复制吗?
继续指教.

 

Similar threads

I
回复
0
查看
578
import
I
I
回复
0
查看
609
import
I
I
回复
0
查看
574
import
I
顶部