gpt4 book ai didi

delphi - T图像未显示

转载 作者:行者123 更新时间:2023-12-02 02:46:53 25 4
gpt4 key购买 nike

当将此组件拖放到表单上时,TImage 不会显示 map 图像(六边形),直到我在表单上拖动该组件,然后它将显示它,直到我停止在表单上拖动它。 (这都是在设计模式下进行的)。怎么让它一直显示?不是只是拖动它时。

   type
THexMap = Class(TScrollingWinControl)

构造函数

Constructor THexMap.Create(AOwner: Tcomponent);
begin
inherited Create(AOwner);

Width := DEFAULT_MAP_WIDTH;
Height := DEFAULT_MAP_HEIGHT;

FCanvas := timage.Create(self);
tempMap := timage.Create(self);

fcanvas.Parent := self;
tempmap.Parent := self;

fCanvas.Width := DEFAULT_MAP_WIDTH;
fCAnvas.Height := DEFAULT_MAP_WIDTH;


{ Set intial property values for component }

//create map
MakeSolidMap;

end;

制作实体 map

Procedure THexMap.MakeSolidMap;
var
p0 : TPoint;
looprow,Loopcol : integer;
begin
TempMap.width := ((HexColumns-1) * round((1.5 * HexRadius))) + (2 * hexRadius);
TempMap.height := ((HexRows) * (2 * rise)) + rise;

With TempMap.Canvas do
begin
{set Background color}
brush.Color := BackColor;
fillrect(rect(0,0,TempMap.Width,TempMap.Height));

{draw Hex's left to right / top to bottom}
for looprow := 1 to HexRows do
begin
for loopcol := 1 to HexColumns do
begin
{compute center coords}
p0 := ConvertCoords(Point(LoopCol,LoopRow),ptROWCOL);

{draw the hex}
DrawSolidHex(Tempmap,bsSolid,hexColor,psSolid,LineColor,P0.X,p0.Y,hexRadius,hex3d);

end;
end;
end;
end;

绘制SolidHex

 procedure THexMap.DrawSolidHex(Target: timage;
FillStyle: TBrushStyle;
FillColor: TColor;
LineStyle: TPenStyle;
LineColor: TColor;
x: Integer;
y: Integer;
Radius: Integer;
button: Boolean);
var
p0,p1,p2,p3,p4,p5,p6:TPoint;
begin
p0 := Point(x,y);

{compute each point based on hex center}
p1.X := p0.X - round(Radius /2);
p1.Y := p0.Y - rise;
p2.X := p0.X + round(Radius/2);
p2.Y := p1.Y;
p3.X := p0.X + Radius;
p3.Y := p0.Y;
p4.X := p2.X;
p4.Y := p0.Y + rise;
p5.X := p1.X;
p5.Y := p4.Y;
p6.X := p0.X - Radius;
p6.Y := p0.Y;

{set color / style of lines}
target.canvas.Pen.Color := LineColor;
target.canvas.Pen.Style := LineStyle;

{set color / style of hex}
target.canvas.Brush.Color := FillColor;
Target.canvas.Brush.Style := FillStyle;

{draw the hex}
target.canvas.Polygon([p1,p2,p3,p4,p5,p6]);

{if desired, draw the boarder for the hex}
if button = true then
begin
with target.canvas do
begin
pen.Mode :=pmCopy;
pen.Color :=clWhite;
moveto(p5.X+1,p5.Y-1);
lineto(p6.X+1,p6.Y);
lineto(p1.X+1,p1.Y+1);
lineto(p2.X-1,p2.Y+1);
pen.Color :=clBlack;
lineto(p3.X-1,p3.Y);
lineto(p4.X-1,p4.Y-1);
lineto(p5.X+1,p5.Y-1);
end;
end;
invalidate;
end;

WndProc

procedure THexMap.WndProc(var Message: TMessage);
const
DISCARD_CURRENT_ORIGIN = nil;
var
R : TRect;
PS : PAINTSTRUCT;
begin
if Message.Msg = WM_PAINT then
begin
if GetUpdateRect( Handle, nil, false ) then
begin
BeginPaint( Handle, PS );
try
R := PS.rcPaint;
bitblt(fCanvas.Canvas.Handle, R.Left, R.Top, R.Width, R.Height, TempMap.Canvas.Handle, R.Left+FOffset.X, R.Top+FOffset.Y, SRCCOPY);
finally
EndPaint( Handle, PS );
end;
end
else
inherited;
end
else
inherited;
end;

最佳答案

没有显示任何内容,因为您已通过传递 WM_PAINT 接管了控件的绘制。在处理 WM_PAINT 时,您不会向 BeginPaint 返回的设备上下文绘制任何内容。您不会调用继承的处理程序,该处理程序将调用Paint,然后绘制子项。因此,您无法控制任何内容。

在我看来,您需要决定是使用视觉控件并让 VCL 绘制它们,还是自己绘制控件。您目前正在尝试两者兼而有之,但两者都没有实现!

我无法建议修复,因为我真的不知道你在做什么。我不明白为什么你有视觉控件并覆盖绘画消息处理程序。要继续前进,您需要选择一种方法或另一种方法。

关于delphi - T图像未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23730864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com