如何使 Winforms 进度条在 C# 中垂直移动?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/597411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 09:43:09  来源:igfitidea点击:

How do I make a winforms progress bar move vertically in C#?

c#winformsuser-interfaceprogress-bar

提问by Krakerjak

I'm working on a WinForms Jukebox.
I'd like to have a vertical ProgressBar for the volume control.

我正在使用 WinForms Jukebox。
我想要一个用于音量控制的垂直 ProgressBar。

Does anyone know how to do that?

有谁知道这是怎么做到的吗?

采纳答案by Daniel LeCheminant

I don't know that I'd use a progress bar to controlthe volume, but to displaythe volume level you could use a user drawn control or you could just resize a label with a background color (that last method is kind of kludgy though)

我不知道我会使用进度条来控制音量,但是要显示音量级别,您可以使用用户绘制的控件,或者您可以只调整带有背景颜色的标签的大小(最后一种方法有点笨拙尽管)

The progress bar isn't meant to take input, no matter what the orientation.

无论方向如何,进度条都不是用来接受输入的。

If you really would like to controlthe volume, consider using a vertical scroll bar, or a trackbar with a vertical orientation.

如果您真的想控制音量,请考虑使用垂直滚动条或垂直方向的轨迹栏。

For what it's worth, there's a discussion on how to create a vertical progress bar on MSDN, where they suggest doing this:

对于它的价值,有关于如何在 MSDN 上创建垂直进度条的讨论,他们建议这样做:

using System; 
using System.Windows.Forms; 

public class VerticalProgressBar : ProgressBar { 
  protected override CreateParams CreateParams { 
    get { 
      CreateParams cp = base.CreateParams; 
      cp.Style |= 0x04; 
      return cp; 
    } 
  } 
}

which sets the PBS_VERTICALflag in Style.

PBS_VERTICAL标志设置为Style.

回答by Ken White

You have to use the ProgressBarRenderer for that. It's documented in MSDN

为此,您必须使用 ProgressBarRenderer。它记录在MSDN 中

The documentation actually shows implementation of a vertical ProgressBar, so it should make it easy for you. :-)

该文档实际上显示了垂直 ProgressBar 的实现,所以它应该让你很容易。:-)