如何在 Delphi 2010 中的 TTrackBar 上设置自定义刻度?
我尝试将刻度样式设置为 tsManual,将最小和最大位置分别设置为 1 和 100,并在 9、19、79 和 89 添加刻度,除了控件自动显示的默认第一个和最后一个刻度之外,根本不显示任何刻度。我尝试了其他值,但没有显示任何值。我的代码是:
TrackBar1.TickStyle := tsManual;
TrackBar1.Min := 1;
TrackBar1.Max := 100;
TrackBar1.SetTick( 9 );
TrackBar1.SetTick( 19 );
TrackBar1.SetTick( 79 );
TrackBar1.SetTick( 89 );
有什么建议吗?我确信我遗漏了一个重要的细节,而且文档也非常稀疏。这是 Delphi 2010 中的一个新的空 VCL Forms 项目,更新为 4。
提前谢谢您。
I tried to set the tick style to tsManual, the min and max position to 1 and 100 respectively and add ticks at 9, 19, 79 and 89 and no ticks are shown at all except the detault first and last which the control automatically shows. I tried other values and none are ever shown. My code is:
TrackBar1.TickStyle := tsManual;
TrackBar1.Min := 1;
TrackBar1.Max := 100;
TrackBar1.SetTick( 9 );
TrackBar1.SetTick( 19 );
TrackBar1.SetTick( 79 );
TrackBar1.SetTick( 89 );
Any suggestions? I'm sure I'm missing an important detail, and the documentation is pretty sparse. This is on a new empty VCL Forms project in Delphi 2010 with update 4.
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果当前未分配 Handle 属性,则 TTrackBar.SetTick() 不会发送 TBM_SETTIC 消息:
直到第一次读取 Handle 属性(而不是在最初创建组件时)才会分配窗口句柄。因此,在调用 SetTick() 之前调用 HandleNeeded():
TTrackBar.SetTick() does not send the TBM_SETTIC message if the Handle property is currently unassigned:
The window handle does not get allocated until the Handle property is read for the first time, not when the component is initially created. As such, call HandleNeeded() before calling SetTick():
我不知道为什么过程 TrackBar1.SetTick 不起作用,但如果您以与过程相同的方式发送消息,它将起作用。您需要将单位 CommCtrl 添加到您的 use 子句中以解析 TBM_SETTIC,如图所示...
希望这会有所帮助!
I don't know why the procedure TrackBar1.SetTick does not work but if you SendMessage the same way the procedure does it will work. You will need to add the unit CommCtrl to your uses clause to resolve TBM_SETTIC as shown...
Hope this helps!
除了
handle
已准备就绪且TickStyle
=tsManual
之外,Frequency
属性还必须设置为多个或,更容易,到 1。Besides the
handle
being ready and theTickStyle
=tsManual
, thefrequency
property must be set to a multiple or, more easily, to 1.