首页 > 解决方案 > Delphi 10.3 社区 PaintBox 重绘功能的问题

问题描述

我目前正在 Delphi 10.3 Community Version 26.0.34749.6593 中制作一个小程序。没有额外的组件。

本质上,我在 TPaintBox 上绘制,它安装在面板中。到目前为止一切正常,但是当通过“PaintBox1.Repaint”重新绘制对象时,对象得到了错误的 BrushStyle(bsSolid,当它们应该有 bsClear 时)当然我试图把它固定下来,但我没有运气。但我发现在以下几点不起作用:

    procedure TForm1.PaintBox1Paint(Sender: TObject);
    var
        i: Integer;
        fig : ^TFigure;
        apen: TPenStyle;
        abrush: TBrushStyle;
        color1,color2: TColor;

    begin
        aPen := PaintBox1.Canvas.Pen.Style;
        aBrush := bsStyle;
        color1 := PaintBox1.Canvas.Brush.Color;
        color2 := PaintBox1.Canvas.Pen.Color;

        for I:=0 to List.Count-1 do
        begin
          fig := List.Items[i];
          case fig.Typ of
                f_Kreis : begin
                          with Paintbox1.Canvas do
                          begin
                            pen.Style := fig.Pen;
                            Brush.Style := fig.Brush;
                            pen.Color := fig.PenColor;
                            brush.Color := fig.BrushColor;
                            Ellipse(fig.X,fig.Y,fig.X2,fig.Y2);
                          end;
                          end;
                f_Rechteck :    begin
                                  with PaintBox1.Canvas do
                                  begin
                                       Pen.Style := fig.Pen;
                                       Brush.Style := fig.Brush;
                                       Pen.Color := fig.PenColor;
                                       Brush.Color := fig.BrushColor;
                                       Rectangle(fig.X,fig.Y,fig.X2,fig.Y2);
                                  end;
                                end;
                f_Line :  begin
                            with PaintBox1.Canvas do
                            begin
                              pen.Style := fig.Pen;
                              brush.Style := fig.Brush;
                              pen.Color := fig.PenColor;
                              brush.Color := fig.BrushColor;
                              MoveTo(fig.X,Fig.Y);
                              LineTo(fig.X2,fig.Y2);
                            end;
                          end;
          end;
        end;



        PaintBox1.Canvas.Pen.Style := aPen;
        bsStyle := aBrush;
        PaintBox1.Canvas.Brush.Color := color1;
        PaintBox1.Canvas.Pen.Color := color2;
     end;

因此,当调用“Brush.Style := fig.Brush;”-Line 时,什么也没有发生。我一步一步走,即使“fig.Brush”是“bsClear”,这些线“Brush.Style”仍然是“bsSolid”

解释: TFigure 是我自己的课程。它包含有关绘图的信息,例如矩形。它是父类。

我想念什么吗。我真的没有想法。谁能告诉我,为什么什么都没发生?

如果您需要更多信息,请告诉我。先感谢您

编辑:

为了测试,我添加了以下行:

if Brush.Style <> fig.Brush then
   ShowMessage('Warnung!');

在下面

Brush.Style := fig.Brush;

尽管 Brush.Style 是 bsSolid 而 fig.Brush 是 bsClear,但它实际上不会将其设置为 false。

标签: windowsdelphipascal

解决方案


您已声明fig : ^TFigure;,但类实例已经是引用(指针)。因此,您正在创建一个指向引用的指针,并像使用该引用一样使用该指针。

删除指针运算符并声明

fig: TFigure;

我无法验证您的代码中是否还有其他错误


推荐阅读