将滚动条隐藏在 Delphi dbgrid 中(即使在调整大小时)
对于我们的 dbgrid,我们希望滚动条始终隐藏。 由于 TDBGrid 没有“滚动条”属性,因此我们使用:
ShowScrollBar(DBGrid1.Handle, SB_VERT, False);
ShowScrollBar(DBGrid1.Handle, SB_HORZ, False);
但是,当我们调整窗口(以及包含 dbgrid 的面板)的大小时,对于 一秒钟滚动条出现,只有在调用后才再次隐藏 以上两种方法。
解决方案是在DrawColumnCell中调用这些方法,但这会导致闪烁 dbgrid 的值,即使 DoubleBuffered 设置为 true。
有什么办法可以永久隐藏滚动条吗?
提前致谢!
For our dbgrid we want the scrollbars to be constantly hidden.
Since TDBGrid doesn't have a 'scrollbars' property, we use:
ShowScrollBar(DBGrid1.Handle, SB_VERT, False);
ShowScrollBar(DBGrid1.Handle, SB_HORZ, False);
However when we resize the window (and the panel containing the dbgrid), for
a second the scrollbars appear and becom hidden again only after recalling
the two above methods.
A solution is to call these methods in DrawColumnCell, but this causes flickering
of the dbgrid, even with DoubleBuffered set to true.
Is there any way to hide the scrollbars permanently?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
隐藏
TDBGrid
中的滚动条://docwiki.embarcadero.com/Libraries/en/Vcl.Grids.TCustomGrid.CreateParams">CreateParams
具有非常短的时间效果。有一个过程UpdateScrollBar
导致滚动条可见。发生这种情况是因为滚动条的可见性是根据显示的数据进行控制的,因此每当数据更改时都会调用此过程。由于每当需要更新滚动条时都会调用此过程,并且由于它是虚拟的,因此是时候覆盖它了。
以下代码示例使用插入类,因此所有
TDBGrid
组件在属于该单位的表格上将表现相同:Hiding the scrollbar of the
TDBGrid
inCreateParams
has a very short time effect. There's the procedureUpdateScrollBar
which causes the scrollbar to be visible. It happens because the scroll bar visibility is controlled depending on the data displayed, thus this procedure is called whenever the data is changed.And since this procedure is called whenever the scrollbar needs to be updated and because it's virtual, it's time to override it.
The following code sample uses the interposed class, so all
TDBGrid
components on the form which belongs to this unit will behave the same:滚动条在
TDBGrid.UpdateScrollBar
中更新。不幸的是这个例程不是虚拟的(至少在 D7 中)。在该例程中,调用SetScrollInfo
,这是一个不发送任何可能被拦截的消息的 Windows 函数。那里没有运气。剩下的唯一可能是重写每当控件更改大小时发送的消息的消息处理程序:
尽管当数据更改或数据集处于活动状态时也会调用
UpdateScrollBar
> 属性更改,这似乎在这里工作而不会闪烁。The scroll bar is updated in
TDBGrid.UpdateScrollBar
. Unfortunately this routine is not virtual (in D7 at least). Within that routine,SetScrollInfo
is called, a Windows function that doesn't send any message that could be intercept. No luck there.The only possibility left is to override the message handler for the message that is send whenever the control changed size:
Although
UpdateScrollBar
is also called when the data is changed or when the dataset'sActive
property changes, this seems to work here without flickering.也许重写
CreateParams()
方法并删除Params.Style
形式的WS_HSCROLL
和WS_VSCROLL
位会有所不同。如果您不想编写自定义后代,您可以尝试使用 类助手 来完成此操作。您还可以将 SetWindowLongPtr API 与
GWL_STYLE
更改窗口的样式,但当由于某种原因重新创建网格窗口时,更改会丢失(因此它不如覆盖可靠)CreateParams
)。Perhaps overriding
CreateParams()
method and removingWS_HSCROLL
andWS_VSCROLL
bits formParams.Style
makes difference. You could try to do it with class helper if you don't want to write custom descendant.You could also use SetWindowLongPtr API with
GWL_STYLE
to change window's style but then the changes are lost when grid's window is recreated for some reason (so it's not as reliable than overridingCreateParams
).