问题描述
有人知道如何在 WinForms 中创建带有多个滑块的轨迹栏吗?我想标记一个范围.另外,是否可以稍微垂直偏移滑块?我的目标是在轨迹栏上方有两个滑块,在其下方有两个滑块.
Does anyone have any idea on how to create a trackbar with multiple sliders in WinForms? I would like to mark a range. Also, is it possible to offset the sliders vertically a little bit? My goal would be to have two sliders above the trackbar, and two below it.
v-----------------v
________________________________________
^------^
推荐答案
您可以通过编写自己的 UserControl
来完成此操作,您可以在其中处理鼠标事件并自行绘制.您将需要多个命中测试区域;每个拇指一个.
You can do this by writing your own UserControl
where you handle the mouse events and painting yourself. You would need several hit test regions; one for each thumb.
要绘制轨迹栏,您需要 ControlPaint
和 System.Windows.Forms.VisualStyles
命名空间.最值得注意的是,VisualStyleElement.TrackBar.ThumbTop
, VisualStyleElement.TrackBar.ThumbBottom
和 VisualStyleElement.TrackBar.Track
分别用于绘制拇指和轨迹.
To draw the trackbar, you would need a combination of ControlPaint
and the theming APIs provided by the System.Windows.Forms.VisualStyles
namespace. Most notably, the VisualStyleElement.TrackBar.ThumbTop
, VisualStyleElement.TrackBar.ThumbBottom
, and VisualStyleElement.TrackBar.Track
for drawing the thumbs and track respectively.
当主题不可用时(例如在 Win2k 上或主题被禁用时),您可以使用 ControlPaint
调用为轨道和拇指绘制框架和按钮.
You use the ControlPaint
calls to draw a frame and buttons for the track and thumbs when theming is unavailable (such as on Win2k or when theming is disabled).
这篇关于Windows窗体的多个滑块轨迹栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!