首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TImage没有出现

TImage没有出现
EN

Stack Overflow用户
提问于 2014-05-19 06:19:27
回答 1查看 649关注 0票数 1

当将该组件拖到窗体上时,TImage将不会显示映射图像(六边形),直到我将该组件拖到窗体上,然后它将显示它,直到停止在窗体上拖动它。(这都是在desgin模式下)。怎么才能让它一直展现出来呢?只是拖着就行了。

代码语言:javascript
复制
   type
      THexMap = Class(TScrollingWinControl)

构造函数

代码语言:javascript
复制
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;

MakeSolidMap

代码语言:javascript
复制
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;

DrawSoildHex

代码语言:javascript
复制
 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

代码语言:javascript
复制
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;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-19 06:27:26

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

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

我不能提出解决办法,因为我真的不知道你在做什么。我不明白为什么你有视觉控制和覆盖油漆消息处理程序。要继续前进,你需要选择一种或另一种方法。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23730864

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档