垂直颠倒的进度条?
我想做一个垂直进度条,所以我发现了这个: 垂直进度条
但是现在如果你有水平进度条,你可以让它从左到右/从右到左工作,所以我希望我的垂直式从上到下工作,而不是像现在一样从下到上工作..
这可能吗?
这是我
public class VerticalProgressBar : ProgressBar
{
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Style |= 0x04;
return cp;
}
}
}
使用 C# .NET 3.5 Windows 窗体的代码
I wanted to do a Vertical Progress Bar so i found this:
Vertical progress bar
But now like if you have Horizitonal Progress Bar you can make it work from LeftToRight / RightToLeft so i want my Vertical one to Work from UpToDown and not from DownToUp like it works now..
Is it possible?
Here is my code
public class VerticalProgressBar : ProgressBar
{
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Style |= 0x04;
return cp;
}
}
}
I'm using C# .NET 3.5 Windows Forms
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
支持视觉样式的代码包含一些错误。此代码:
必须替换为此代码:
并且我重新发布了没有此错误的完整源代码:
Code, that support visual styles contains some bug. This code:
must be replaced with this one:
And i repost full source code without this bug:
似乎没有任何 CreateParams 支持反向垂直 ProgressBar。这些是来自 Windows API 的样式参数:
我尝试更改 RightToLeft 值,但无济于事。似乎也没有办法任意旋转 Windows 窗体控件。
一种可能的解决方案是使用 WPF ProgressBar。您可以将其旋转 90 度,它应该可以满足您的要求。另一种选择是使用第三方进度条控件或创建自定义呈现的控件。渲染一个简单的平面进度条应该相当容易。
There doesn't seem to be any CreateParams that support inverted vertical ProgressBar. These are the style parameters from the Windows API:
I tried changing the RightToLeft values to no avail. There also doesn't seem to be a way to arbitrarily rotate a Windows Forms control.
A possible solution may be to use the WPF ProgressBar. You could rotate it 90 degrees and it should do what you're looking for. Another option is to use a third party Progressbar control or create a custom rendered one. It should be fairly easy to render a simple flat progressbar.
你必须像这样重写 OnPaint() :
现在你可以像下面一样使用它
您链接的垂直进度栏和LeftToRight / RightToLeft功能将模仿普通ProgressBar中的进度条(关于进度绘制方向) )。
You have to override OnPaint() like this:
Now you can use it in the same way as
Vertical progress bar you linked and LeftToRight / RightToLeft functionality will mimic the one from normal ProgressBar (regarding progress drawing orientation).
我注意到上面的代码不适用于视觉样式。这是垂直进度条的改进版本,应涵盖视觉样式:
我必须为自下而上的进度条绘制单独的块,因为我想保持其他进度条的外观和感觉。否则,该条形图就会看起来像是从中间绘制的。
I noticed the code above does not work well with visual styles. Here is an improved version of vertical progress bar that should cover visual styles:
I had to draw separate chunks for bottom-up progress bar because I wanted to keep look and feel of other progress bars. Otherwise the bar would have appeared to be drawn from the middle.