delphi里面Treeview这个控件里面的TreeNode列表是怎么在VCL里面绘制的?我想重新写一个这样的控件,把后面的文字变成二行,然后进行一些别的操作。这个问题我在网上找了他妈的N久都没有找到?
解决方案 »
- 有没有人在自己开发的控件中引入字符串类型的属性?
- 哪位有DevExpress的帮助文档,最好是中文的,主要是想要cxgrid的帮助文档.
- 请教怎么快速把一个单元的所有编辑框初始化为空
- 有关webbrowse无法访问本地机器上网页的问题~~
- ActiveForm如何获得所在htm文件中的参数
- 陏闷,散分!顺便问一下,做三层结构要注意的地方,比如接口的封装等。
- Delphi中如何实现下面的功能:) 谢谢
- 我现在的公司
- 关于把jpg写入流进行网络传输的问题?
- 难道老大们没有碰到过这样的怪问题(BDE/ACCESS),我....
- 如何将excel文件与access文件相互转换
- delphi 与数据库中数据操作问题
你可以定义节点的 OnCustomDrawItem 事件,实现节点绘制方面的特殊要求。
看看TCustomTreeView的CreateParam方法如何作的就知道了
VCL代码
procedure TCustomTreeView.CreateParams(var Params: TCreateParams);
const
BorderStyles: array[TBorderStyle] of DWORD = (0, WS_BORDER);
LineStyles: array[Boolean] of DWORD = (0, TVS_HASLINES);
RootStyles: array[Boolean] of DWORD = (0, TVS_LINESATROOT);
ButtonStyles: array[Boolean] of DWORD = (0, TVS_HASBUTTONS);
EditStyles: array[Boolean] of DWORD = (TVS_EDITLABELS, 0);
HideSelections: array[Boolean] of DWORD = (TVS_SHOWSELALWAYS, 0);
DragStyles: array[TDragMode] of DWORD = (TVS_DISABLEDRAGDROP, 0);
RTLStyles: array[Boolean] of DWORD = (0, TVS_RTLREADING);
ToolTipStyles: array[Boolean] of DWORD = (TVS_NOTOOLTIPS, 0);
AutoExpandStyles: array[Boolean] of DWORD = (0, TVS_SINGLEEXPAND);
HotTrackStyles: array[Boolean] of DWORD = (0, TVS_TRACKSELECT);
RowSelectStyles: array[Boolean] of DWORD = (0, TVS_FULLROWSELECT);
begin
//调用Windows方法来创建一个TreeView组件,其它的绘制动作其实也是Windows实现的
InitCommonControl(ICC_TREEVIEW_CLASSES);
inherited CreateParams(Params);
CreateSubClass(Params, WC_TREEVIEW);
with Params do
begin
Style := Style or LineStyles[FShowLines] or BorderStyles[FBorderStyle] or
RootStyles[FShowRoot] or ButtonStyles[FShowButtons] or
EditStyles[FReadOnly] or HideSelections[FHideSelection] or
DragStyles[DragMode] or RTLStyles[UseRightToLeftReading] or
ToolTipStyles[FToolTips] or AutoExpandStyles[FAutoExpand] or
HotTrackStyles[FHotTrack] or RowSelectStyles[FRowSelect];
if Ctl3D and NewStyleControls and (FBorderStyle = bsSingle) then
begin
Style := Style and not WS_BORDER;
ExStyle := Params.ExStyle or WS_EX_CLIENTEDGE;
end;
WindowClass.style := WindowClass.style and not (CS_HREDRAW or CS_VREDRAW);
end;
end;其实TButton,TEdit也是这样实现的,Delphi没有绘制过程
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
//ListBox.OnDrawItem事件
var
ImgRect, MemoRect: TRect;
Cnvs: TCanvas;
B: TBitmap;
S, Memo: string;
iPos: Integer;
begin
Cnvs := ListBox1.Canvas;
ImgRect := Rect;
ImgRect.Right := ImgRect.Left + (ImgRect.Bottom - ImgRect.Top); //画图区域 if odSelected in State then
begin
Cnvs.Brush.Color := clSkyBlue;
Cnvs.Pen.Color := clNavy;
end
else
begin
Cnvs.Brush.Color := ListBox1.Color;
Cnvs.Pen.Color := ListBox1.Color;
end;
Cnvs.Brush.Style := bsSolid;
Cnvs.Rectangle(Rect); Cnvs.Brush.Style := bsClear;
if ImageList.Count > 0 then
begin
B := TBitmap.Create;
try
ImageList.GetBitmap(0, B);
B.PixelFormat := pf24bit;
B.Transparent := True;
InflateRect(ImgRect, -2, -2);
Cnvs.StretchDraw(ImgRect, B);
finally
B.Free;
end;
end; Rect.Left := ImgRect.Right;
MemoRect := Rect;
MemoRect.Top := (Rect.Top + Rect.Bottom) div 2;
Rect.Bottom := MemoRect.Top;
S := ListBox1.Items[Index]; iPos := Pos(#9, S);
Memo := Copy(S, iPos + 1, Length(S)); //提取备注
S := Copy(S, 1, iPos - 1); //提取名称
Cnvs.Font.Assign(ListBox1.Font);
DrawText(Cnvs.Handle, PChar(S), -1,
Rect, DT_SingleLine or DT_VCENTER); //垂直、水平居中 画名字 Cnvs.Font.Color := clGrayText;
DrawText(Cnvs.Handle, PChar(Memo), -1,
MemoRect, DT_SingleLine or DT_VCENTER); //垂直、水平居中 画名字
end;procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.Style := lbOwnerDrawVariable; //自己画每一项,项高度可调
ListBox1.ItemHeight := 30;
ListBox1.Clear;
//名称+#9+备注
ListBox1.Items.Add('yao518'#9 + '一剑飘雪');
ListBox1.Items.Add('blazingfire'#9 + '...该充电了...');
ListBox1.Items.Add('yao518'#9 + '一剑飘雪');
ListBox1.Items.Add('blazingfire'#9 + '...该充电了...');
end;