捐赠 | 广告 | 注册 | 发布 | 上传 | 关于我们    
  粤ICP备10103342号-1 DELPHI盒子 | 盒子文章 | 盒子问答悬赏 | 最新更新 | 盒子检索 | 下载中心 | 高级搜索    
  精品专区 | 繁體中文 | 奖励公告栏 | 直通车账号登陆 | 关闭GOOGLE广告 | 临时留言    
 
广告
评论:自画 TListBox 界面演示
dalas 31076 2007/9/3 21:14:10
procedure TMainForm.lbxMainDrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
function GetText(const Text:String):String;
const iWidth = 32 + 10 + 5; //图标宽32 + 间隔10 + 右边保留5 (单位:象素)
var
  tmpStr:String;
  iIndex,i,tmpWidth:Integer;
begin
  Result:=Text;
  tmpWidth:=lbxMain.Canvas.TextWidth(Text);
  if Rect.Left + iWidth + tmpWidth > Rect.Right - Rect.Left then
  begin
    tmpWidth:=Rect.Right-Rect.Left;
    tmpStr:='';
    for iIndex:=1 to Length(Text) do
    begin
      tmpStr:=tmpStr+Text[iIndex];
      if tmpWidth<=lbxMain.Canvas.TextWidth(tmpStr) + iWidth then
      begin
        for i:=1 to 3 do
        begin
          Result:=Copy(tmpStr,1,iIndex-i)+'...';
          if tmpWidth>lbxMain.Canvas.TextWidth(Result) + iWidth then
          Break;
        end;
        Break;
      end;
    end;
  end;
end;
var
  strTemp: string;
begin

  ......

  // Item的第一行文字
  lbxMain.Canvas.TextOut(Rect.Left + 32 + 10, Rect.Top + 4,
    GetText(lbxMain.Items[Index]));
  strTemp := pStrList.Strings[Index];
  // Item的第二行文字
  lbxMain.Canvas.TextOut(Rect.Left + 32 + 10, Rect.Top + 18,
    GetText(Copy(strTemp, 1, Pos(#13, strTemp) - 1)));
  // Item的第三行文字
  lbxMain.Canvas.TextOut(Rect.Left + 32 + 10, Rect.Top + 32,
    GetText(Copy(strTemp, Pos(#13, strTemp) + 1, Length(strTemp))));
end;

这么修改后就可以把超长的字符以'...'代替,不会破坏右边框。
GetText 函数比较繁琐,有谁简化后希望能贴出来!
dalas 31075 2007/9/3 21:07:18
没有处理文字超长的情况,右边的自画边框会被超长的文字破坏,很难看
beginner999 30949 2007/8/22 11:31:10
DrawFocusRect(lbxMain.Canvas.Handle, &Rect); 把取地址的&去掉就行了。
qh_liyan 30938 2007/8/21 17:01:24
 DrawFocusRect(lbxMain.Canvas.Handle, &Rect);还有这问题
qh_liyan 30937 2007/8/21 17:00:12
为什么我一打开就说Invalid resouse file:Error reading file
ccrun 30848 2007/8/14 12:34:34
当初我就是模仿CnPack的样式写的,不过CnPack的自画貌似没有消除那个拥有焦点时的虚框。
sail2000 30823 2007/8/13 10:06:13
如果連滾動條可以自由自畫就真的很好了!
dunlee 30816 2007/8/13 8:47:43
楼主不厚道,系统退出还得进入任务管理器里面杀进程。
guanbo 30813 2007/8/13 7:42:09
貌似跟CnPack中设置里的LISTBOX是一样的
pnnyy 30811 2007/8/13 1:29:59
想不到ListBox还有画出这样的效果,太神奇了,支持
第一页 上一页 下一页 最后页 有 10 条纪录 共1页 1 - 10
 用户名:
 密 码:
自动登陆(30天有效)
 
  DELPHI盒子版权所有 技术支持:深圳市麟瑞科技有限公司 1999-2024 V4.01 粤ICP备10103342号-1 更新RSS列表