如何使用 vb.net 自定义进度条
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20558871/
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
how to customize a progress bar using vb.net
提问by JasonBourne
I was trying to creating a progress bar that was color coded in relation to the value. For example, from 0-35, the progress bar should be red-colored and above 35, green colored. Any idea how I can go about doing it?
我试图创建一个与值相关的颜色编码的进度条。例如,从 0 到 35,进度条应为红色,而在 35 以上,则为绿色。知道我该怎么做吗?
If ProgressBar1.Value >= 35 Then
ProgressBar1.BackColor = Color.Green
Else
ProgressBar1.BackColor = Color.Red
End If
P.S in the same progressbar, both the colors have to shown based on the values
PS 在同一个进度条中,两种颜色都必须根据值显示
回答by Edper
You need to change settings on this one.
您需要更改此设置。
Go to Project --> [WindowsApplication] Properties
On Application Tab -- Uncheck Enable Visual Styles
However, be warned for there is a visual change on your progress bar as you will see.
但是,请注意,您将看到进度条上的视觉变化。
You could then probably code like this:
然后你可能可以这样编码:
If (ProgressBar1.Value > 35) Then
ProgressBar1.ForeColor = Color.Red
Else
ProgressBar1.ForeColor = Color.Green
End If
回答by Engr. S.M. Inuwa
You can possibly use this method.
您可以使用这种方法。
Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Enum ProgressBarColor
Green = &H1
Red = &H2
Yellow = &H3
End Enum
Private Shared Sub ChangeProgBarColor(ByVal ProgressBar_name As Windows.Forms.ProgressBar, ByVal ProgressBar_Color As ProgressBarColor)
SendMessage(ProgressBar_name.Handle, &H410, ProgressBar_Color, 0)
End Sub
then add your condition statement by calling the function above e.g.
然后通过调用上面的函数来添加您的条件语句,例如
If ProgressBar1.Value >= 35 Then
ChangeProgBarColor(ProgressBar1, ProgressBarColor.Red)
Else
ChangeProgBarColor(ProgressBar1, ProgressBarColor.Yellow)
End If
回答by Levi
The position of the progress bar is stored in ProgressBar1.value. You can check this value in an Ifstatement and change the color using ProgressBar1.ForeColor
进度条的位置存储在ProgressBar1.value. 您可以在If语句中检查此值并使用更改颜色ProgressBar1.ForeColor
eg:
例如:
If ProgressBar1.value > 35 Then
ProgressBar1.ForeColor = Color.Lime
End If
I hope this helps ;)
我希望这有帮助 ;)
Edit:Try using ProgressBar1.ForeColorrather than ProgressBar1.BackColor
编辑:尝试使用ProgressBar1.ForeColor而不是ProgressBar1.BackColor

