Multiple slider trackbar for windows forms

佐手、 提交于 2021-02-17 20:28:20

问题


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
________________________________________
                                ^------^

回答1:


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.

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.

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).




回答2:


You can draw your own using ControlPaint to make sure the rendering is consistent with the rest of your UI.



来源:https://stackoverflow.com/questions/581568/multiple-slider-trackbar-for-windows-forms

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!