注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

珠海渔郎之电子网档

项目管理 + 程序开发 + Delphi + 电脑应用 + 数码 + 进化感悟

 
 
 

日志

 
 

显示换行的ListBox  

2009-10-31 19:26:45|  分类: Delphi |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

(*//
标题:显示换行的ListBox
说明:如显示聊天记录
日期:2005-02-05
设计:Zswang
支持:wjhu111@21cn.com
//*)

//*******Begin 修改日志*******//
//2005-02-05 Zswang No.1 新建
//------------------------------------------------------------------------------
//2003-02-07 Zswang No.1 完善 加入自动换行的属性
//*******End 修改日志*******//

unit HistoryBox;

interface

uses
  Windows, Messages, SysUtils, Classes, Controls, StdCtrls, Graphics, Forms;

type
  THistoryBox = class(TCustomListBox)
  private
    FWordWrap: Boolean;
    procedure SetWordWrap(const Value: Boolean);
    { Private declarations }
  protected
    { Protected declarations }
    procedure DrawItem(Index: Integer; Rect: TRect;
      State: TOwnerDrawState); override;
    procedure MeasureItem(Index: Integer; var Height: Integer); override;
    procedure Resize; override;
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
  published
    { Published declarations }
    property WordWrap: Boolean read FWordWrap write SetWordWrap default True;   //2003-02-07 Zswang No.1
    property AutoComplete;
    property Align;
    property Anchors;
    property BevelEdges;
    property BevelInner;
    property BevelKind default bkNone;
    property BevelOuter;
    property BiDiMode;
    property BorderStyle;
    property Color;
    property Columns;
    property Constraints;
    property Ctl3D;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Enabled;
    property ExtendedSelect;
    property Font;
    property ImeMode;
    property ImeName;
    property IntegralHeight;
    property ItemHeight;
    property Items;
    property MultiSelect;
    property ParentBiDiMode;
    property ParentColor;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ScrollWidth;
    property ShowHint;
    property Sorted;
    property TabOrder;
    property TabStop;
    property TabWidth;
    property Visible;
    property OnClick;
    property OnContextPopup;
    property OnData;
    property OnDataFind;
    property OnDataObject;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnDrawItem;
    property OnEndDock;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMeasureItem;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnStartDock;
    property OnStartDrag;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Zswang', [THistoryBox]);
end;

{ THistoryBox }

const
  cWordWraps: array[Boolean] of Word = (0, DT_WORDBREAK);

constructor THistoryBox.Create(AOwner: TComponent);
begin
  inherited;
  FWordWrap := True;
  Style := lbOwnerDrawVariable;
end;

procedure THistoryBox.DrawItem(Index: Integer; Rect: TRect;
  State: TOwnerDrawState);
var
  vRect: TRect;
  S: string;
begin
  inherited;
  S := Items[Index];
  Canvas.FillRect(Rect);
  vRect := Rect;
  if Odd(Index) then
    Canvas.Font.Color := clRed
  else Canvas.Font.Color := clBlue;
  DrawText(Canvas.Handle, PChar(S), Length(S), vRect,
    DT_LEFT or cWordWraps[FWordWrap]);
end;

procedure THistoryBox.MeasureItem(Index: Integer; var Height: Integer);
var
  vRect: TRect;
  S: string;
begin
  inherited;
  S := Items[Index];
  vRect := ClientRect;
  DrawText(Canvas.Handle, PChar(S), Length(S), vRect,
    DT_LEFT or cWordWraps[FWordWrap] or DT_CALCRECT);
  Height := vRect.Bottom - vRect.Top;
end;

procedure THistoryBox.Resize;
var
  I: Integer;
begin
  inherited;
  if not FWordWrap then Exit;
  Items.BeginUpdate;
  for I := 0 to Items.Count - 1 do Items := Items;
  Items.EndUpdate;
end;

procedure THistoryBox.SetWordWrap(const Value: Boolean);
begin
  if FWordWrap = Value then Exit;
  FWordWrap := Value;
  Resize;
end;

end.

效果图:

2009年10月31日 - 珠海渔郎 - 珠海渔郎之电子网档

procedure TForm1.FormCreate(Sender: TObject);

begin
  FHistoryBox := THistoryBox.Create(Self);
  FHistoryBox.Parent := Self;
  FHistoryBox.Align := alClient;
  FCharHeight := FHistoryBox.Canvas.TextHeight('|');
  Font.Name := '宋体';
  Font.Size := 9;

FHistoryBox.Items.Add( '(2005-01-11 11:13:13) 拉灯(410465996)'#13#10 + '投我一票吧!'#13#10 ); FHistoryBox.Items.Add( '(2005-01-11 11:14:56) 拉灯(410465996)'#13#10 + '那我只好去CSDN灌点水了'#13#10 ); FHistoryBox.Items.Add( '(2005-02-04 11:12:44) CoolSlob(7975379)'#13#10 + '明天可以回家了'#13#10 ); FHistoryBox.Items.Add( '(2005-01-11 11:14:25) 布石(356213398)'#13#10 + '昨天没有上网吗?'#13#10 + '看你进天的表现,:)'#13#10 ); FHistoryBox.Items.Add( '(2005-01-13 17:39:03) Ehomsoft(18270172)'#13#10 + '在某个月黑风高的晚上。。。'#13#10 + '我用我的独门武器,刷票机,找了台肉机,把第一页作弊的全刷黑了'#13#10 ); end;

  评论这张
 
阅读(2078)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017