请问有哪个控件可以像QQ那样,在listbox的item前面加图片吗? 请问有哪个控件可以像QQ那样,在listbox的item前面加图片吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用TREEVIEW不是很好吗?可以和IMAGELIST共同使用 楼上的朋友你好,但是我不想要treeview那些树的虚线阿。有没有办法呢? 应该是没有 要是有了 不就象word一样强大了? 可以给ListBox的加载重绘事件。OnDrawItem来修改Item。以下是CnWizard的ListBox重绘的代码,http://www.cnvcl.orgprocedure TCnWizConfigForm.lbWizardsDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);var ListBox: TListBox; Canvas: TCanvas; ARect: TRect; R: TRect; Wizard: TCnBaseWizard; x, y: Integer; Bmp: TBitmap;begin if not (Control is TListBox) then Exit; ListBox := TListBox(Control); Wizard := TCnBaseWizard(ListBox.Items.Objects[Index]); // 创建临时位图以消除闪烁 Bmp := TBitmap.Create; try Bmp.PixelFormat := pf24bit; Bmp.Width := RectWidth(Rect); Bmp.Height := RectHeight(Rect); ARect := Bounds(0, 0, Bmp.Width, Bmp.Height); R.Left := ARect.Left + 4; R.Right := ARect.Right - 5; R.Top := ARect.Top + 2; R.Bottom := ARect.Bottom - 2; Canvas := Bmp.Canvas; Canvas.Font.Assign(ListBox.Font); Canvas.Brush.Style := bsSolid; Canvas.Brush.Color := ListBox.Color; Canvas.FillRect(ARect); Canvas.Brush.Color := csShadowColor; Canvas.RoundRect(R.Left + 1, R.Top + 1, R.Right + 1, R.Bottom + 1, 8, 8); if odSelected in State then begin Canvas.Brush.Color := csSelectedColor; Canvas.Font.Color := clBlue; end else if FActives[Index] then begin Canvas.Brush.Color := csNormalColor; Canvas.Font.Color := clBlack; end else begin Canvas.Brush.Color := csNormalColor; Canvas.Font.Color := clGray; end; Canvas.RoundRect(R.Left, R.Top, R.Right, R.Bottom, 8, 8); //这里加载图标,有些大了点,根据自己需要修改好高度 if Wizard.Icon <> nil then Canvas.Draw(R.Left + 4, R.Top + (R.Bottom - R.Top - Wizard.Icon.Height) div 2, Wizard.Icon); x := R.Left + 42; y := R.Top + 2; //如下输出文字,Item本身的文字输出已经作废。也是根据情况自己修改…… Canvas.TextOut(x, y, SCnWizardNameStr + Wizard.WizardName); Inc(y, 12); if FActives[Index] then Canvas.TextOut(x, y, SCnWizardStateStr + SCnWizardActiveStr) else Canvas.TextOut(x, y, SCnWizardStateStr + SCnWizardDisActiveStr); Inc(y, 12); Canvas.TextOut(x, y, SCnWizardShortCutStr + ShortCutToText(FShortCuts[Index])); BitBlt(ListBox.Canvas.Handle, Rect.Left, Rect.Top, Bmp.Width, Bmp.Height, Canvas.Handle, 0, 0, SRCCOPY); finally Bmp.Free; end;end; 如果最方便加载图片,TreeView和ListView都可以。TreeView自然可以把虚线去掉,很简单。ListView的详细列表方式就可以。如果你要ListBox,就是重绘Item了。自己权衡。 谢谢楼上的兄弟了。问题解决了,原来TreeView去掉虚线真的很简单,呵呵。给你分了。 多线程同步? 请问如何防止程序多个运行 有关OPENPRINTER 关于TreeView.Item. Data的内存分配问题(一个不容易的问题) 求救 求教,怎样在DBGRID中实现象EXCEL一样的多行插入式粘贴或块粘贴?真的没有好办法吗!! 谁知道哪儿有powerpoint下载? 如何让应用程序不在任务条上显示 modem兼容性问题(在线等候)。。。。。。 几种方法的比较,哪个更好? 寻找 delphi7 serial Nmber: 和 Authorization key 升到3星,同时庆祝看论坛cpu的占用率终于低下来了~~
Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
ListBox: TListBox;
Canvas: TCanvas;
ARect: TRect;
R: TRect;
Wizard: TCnBaseWizard;
x, y: Integer;
Bmp: TBitmap;
begin
if not (Control is TListBox) then Exit;
ListBox := TListBox(Control);
Wizard := TCnBaseWizard(ListBox.Items.Objects[Index]); // 创建临时位图以消除闪烁
Bmp := TBitmap.Create;
try
Bmp.PixelFormat := pf24bit;
Bmp.Width := RectWidth(Rect);
Bmp.Height := RectHeight(Rect);
ARect := Bounds(0, 0, Bmp.Width, Bmp.Height); R.Left := ARect.Left + 4;
R.Right := ARect.Right - 5;
R.Top := ARect.Top + 2;
R.Bottom := ARect.Bottom - 2; Canvas := Bmp.Canvas;
Canvas.Font.Assign(ListBox.Font);
Canvas.Brush.Style := bsSolid;
Canvas.Brush.Color := ListBox.Color;
Canvas.FillRect(ARect);
Canvas.Brush.Color := csShadowColor;
Canvas.RoundRect(R.Left + 1, R.Top + 1, R.Right + 1, R.Bottom + 1, 8, 8); if odSelected in State then
begin
Canvas.Brush.Color := csSelectedColor;
Canvas.Font.Color := clBlue;
end
else if FActives[Index] then
begin
Canvas.Brush.Color := csNormalColor;
Canvas.Font.Color := clBlack;
end
else
begin
Canvas.Brush.Color := csNormalColor;
Canvas.Font.Color := clGray;
end;
Canvas.RoundRect(R.Left, R.Top, R.Right, R.Bottom, 8, 8); //这里加载图标,有些大了点,根据自己需要修改好高度
if Wizard.Icon <> nil then
Canvas.Draw(R.Left + 4, R.Top + (R.Bottom - R.Top - Wizard.Icon.Height) div 2, Wizard.Icon); x := R.Left + 42;
y := R.Top + 2; //如下输出文字,Item本身的文字输出已经作废。也是根据情况自己修改……
Canvas.TextOut(x, y, SCnWizardNameStr + Wizard.WizardName);
Inc(y, 12);
if FActives[Index] then
Canvas.TextOut(x, y, SCnWizardStateStr + SCnWizardActiveStr)
else
Canvas.TextOut(x, y, SCnWizardStateStr + SCnWizardDisActiveStr);
Inc(y, 12);
Canvas.TextOut(x, y, SCnWizardShortCutStr + ShortCutToText(FShortCuts[Index])); BitBlt(ListBox.Canvas.Handle, Rect.Left, Rect.Top, Bmp.Width, Bmp.Height,
Canvas.Handle, 0, 0, SRCCOPY);
finally
Bmp.Free;
end;
end;
给你分了。