如何在Delphi中使用滚动条找到网格组件的实际宽度 [英] How to find the actual width of grid component with scrollbar in Delphi

查看:15
本文介绍了如何在Delphi中使用滚动条找到网格组件的实际宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网格组件 (DBGrid),上面有很多列.由于列数较多,因此创建了滚动条,因此网格的某些部分仍然隐藏.我需要找出DBGrid的实际宽度是多少,包括由于滚动条而未显示的部分.但是 Width 属性只给出了组件本身的宽度.有人有什么想法吗?

I have a grid component (DBGrid) which has lots of columns on it. Because of large number of columns, a scrollbar was created, and thus some part of grid remains hidden. I need to find out what is the real width of DBGrid, including the part which is not shown due to scroll bar. But Width property gives only the width of the component itself. Anybody has any idea?

推荐答案

也许这可能会有所帮助.它是 TDBGrid 的类助手的一部分,它自动调整最后一列的大小,以便网格没有空白空间.应该很容易根据您的需要进行调整.

Perhaps this may be helpful. It is part of a class helper for TDBGrid that auto sizes the last column, so that the grid has no empty space. Should be easy to adjust to your needs.

您可能已经注意到,CalcDrawInfo 方法正是您要寻找的.由于它是受保护的,您可以使用类助手或通常的受保护的黑客来处理它.

As you may notice, the CalcDrawInfo method is what you are seeking for. As it is protected you can either use a class helper or the usual protected-hack to get hands on it.

procedure TDbGridHelper.AutoSizeLastColumn;
var
  DrawInfo: TGridDrawInfo;
  ColNo: Integer;
begin
  ColNo := ColCount - 1;
  CalcDrawInfo(DrawInfo);
  if (DrawInfo.Horz.LastFullVisibleCell < ColNo - 1) then Exit;

  if (DrawInfo.Horz.LastFullVisibleCell < ColNo) then
    ColWidths[ColNo] := DrawInfo.Horz.GridBoundary - DrawInfo.Horz.FullVisBoundary
  else
    ColWidths[ColNo] := ColWidths[ColNo] + DrawInfo.Horz.GridExtent - DrawInfo.Horz.FullVisBoundary
end;

这篇关于如何在Delphi中使用滚动条找到网格组件的实际宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆