如何定义自绘Label控件,我的控件为动态生成的,大小用户可以自己调,我想实现上下的居中对齐功能,怎样捕捉控件的自绘消息?

解决方案 »

  1.   

    procedure onpaint ;override;
      

  2.   

    delphi的label本来就有上下居中功能
    属性设置
    AutoSize := False;
    Alignment := taCenter;
    Layout := tlCenter;给分给分!!
      

  3.   


       可以参考以下:   去查一下 TextOutW 的API函数,有上下居中的函数,也可以设置参数。   覆盖:procedure Paint;override;
       label 支持 uncode 编码:...Tlxj3DLabel = class(TGraphicControl)privte
      ...
      FCaption:WideString;
      procedure SetCaption(Value:WideString);
      ...
    protected
      ...
      procedure Paint;override;
      ...
    published
      ...
      propetry Caption : WideString read fCaption wirte SetCaption;
      ...procedure lxj3DLabel.SetCaption(Value:WideString);
    begin
      fCaption:=Value;
      RePaint;
    end;procedure lxj3DLabel.Paint;
    var
      WS:WideString;
    begin
      ...
      WS:=fCaption;
      TextOutW(Canvas.Handle,X,Y,PWideChar(WS),Length(WS));
      ...
    end;基本原理,从TGraphicControl派生出新的lxj3DLabel控件,
    用WideString类型取代fCaption以前的String类型;
    覆盖Paint方法,用TextOutW函数取代TextOut函数,直接从 uncode 编码页输出字符。以上VCL在任何语言的windows版本下,都不会显示乱码。label的uncode问题解决了,请教各位 edit 的 uncode 问题如何解决了???  原贴地址: 
      http://community.csdn.net/Expert/topic/4886/4886915.xml?temp=.2467615
      

  4.   

    hpoi(淹死的鱼) ( ) 信誉:100 ,真是感谢你,你的答案是我最想要的。