不是说好不改字体么。。
而且这样的效果是,如果AutoSize=False,没字的地方直接没有线。。别和我说加空格

解决方案 »

  1.   


    type
      TUnderLineLabel = class(TLabel)
      protected
          procedure Paint; override;
      end;
    procedure TUnderLineLabel.Paint;
    begin
      inherited;
      with Canvas do begin
        Pen.Style := psSolid;  //实线
        Pen.Color := clBlack;   //线条颜色
        MoveTo(0 , ClientRect.Bottom-1);
        LineTo(ClientRect.Right,ClientRect.Bottom-1);
      end;
    end;
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TmyLabel = class(TLabel)
        procedure Paint; override;
      end;
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}{ TmyLabel }procedure TmyLabel.Paint;
    begin
      inherited;
      self.Canvas.Pen.Color := clred;
      self.Canvas.MoveTo(0,self.Height - 1);
      self.Canvas.LineTo(self.Width,self.Height - 1);
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
     with TmyLabel.Create(self) do
     begin
          AutoSize := False;
          Caption := '测试';
       Width := 100;
       Height := 13;
       left := 50;   top := 50;
       Parent := self;
     end;
    end;end.
    这个???
      

  3.   

    尼玛居然成功了。什么原理,我override TCustomLabel 同样是protected的DoDrawText为啥就不行捏?TCustomLabel里的声明:
      protected
        procedure AdjustBounds; dynamic;
        procedure DoDrawText(var Rect: TRect; Flags: Longint); dynamic;而Paint里面是如下这样:
      with Canvas do
      begin
      ..............
        DoDrawText(Rect, DrawStyle);
      end;于是我就override了这个DoDrawText,加了画线代码,咋就失败了,求解
      

  4.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TmyLabel = class(TLabel)
        procedure Paint; override;
        procedure DoDrawText(var Rect: TRect; Flags: Longint);override;
      end;
      TForm1 = class(TForm)
        Button1: TButton;    procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}{ TmyLabel }procedure TmyLabel.DoDrawText;
    begin
      inherited;
      self.Canvas.Pen.Color := clred;
      self.Canvas.MoveTo(0,self.Height - 1);
      self.Canvas.LineTo(self.Width,self.Height - 1);end;procedure TmyLabel.Paint;
    begin
      inherited;end;procedure TForm1.Button1Click(Sender: TObject);
    begin
     with TmyLabel.Create(self) do
     begin
          AutoSize := False;
          Caption := '测试';
       Width := 100;
       Height := 13;
       left := 50;   top := 50;
       Parent := self;
     end;
    end;end.不懂你意思。
      

  5.   

    嗯意思就是,TCustomLabel里面有两个protected的方法,一个叫DoDrawText,一个叫Paint,其中Paint会调用DoDrawText,而且这个DoDrawText是动态的。但是在实际写子类(派生控件)的时候,override的却是Paint方法,总感觉不对劲额。
      

  6.   

    看了你的源码发现还是要再覆盖一次paint方法,也不懂为啥,什么原理哦