我试图更改自定义控件的进度条的颜色。我尝试了很多方法,比如使用下面的发送消息功能:
<DllImport("User32.Dll")> _ Public Shared Function SendMessage(hwnd As Integer, wMsg As Integer, wParam As Integer, lParam As Integer) As Integer End Function
Public Const PBM_SETBKCOLOR As Integer = &H2001
Public Const PBM_SETBARCOLOR As Integer = &H409
Public Sub SetProgressBackColor(c As Color)
Dim a As Integer = Convert.ToInt32(c.R.ToString())
Dim b As Integer = Convert.ToInt32(c.G.ToString())
Dim d As Integer = Convert.ToInt32(c.B.ToString())
Dim tot As Integer = Convert.ToInt32(ColorTranslator.ToOle(Color.FromArgb(a, b, d)).ToString())
Dim j As Integer = Me.PercentFull.Handle.ToInt32()
SendMessage(j, PBM_SETBKCOLOR, 0, tot)
End Sub
Public Sub SetProgressForeColor(c As Color)
Dim a As Integer = Convert.ToInt32(c.R.ToString())
Dim b As Integer = Convert.ToInt32(c.G.ToString())
Dim d As Integer = Convert.ToInt32(c.B.ToString())
Dim tot As Integer = Convert.ToInt32(ColorTranslator.ToOle(Color.FromArgb(a, b, d)).ToString())
Dim j As Integer = Me.PercentFull.Handle.ToInt32()
SendMessage(j, PBM_SETBARCOLOR, 0, tot)
End Sub
但这对我没有用,我可以看到任何改变。
对于我来说,更改此控制的前景色的最佳方式是什么?我不能使用PercentFull.ForeColor,因为我将启用xp样式。
由于
答案 0 :(得分:1)
BackColor
只是发送此消息
正如文档所述,
启用视觉样式时,此消息无效。
你不能这样做。
答案 1 :(得分:1)
在CodeProject上,http://www.codeproject.com/Articles/9635/A-Smooth-ProgressBar-for-everyone-Part-Duex,Stumpy创建了一个SmoothProgressBar,允许您创建具有可变颜色的进度条。看看吧。
答案 2 :(得分:0)
感谢您的帮助,但我决定使用以下内容:
SendMessage(PercentFull.Handle,&amp; H400 + 16,&amp; H2,0)'错误;红
SendMessage(PercentFull.Handle,&amp; H400 + 16,&amp; H3,0)'暂停;黄
SendMessage(PercentFull.Handle,&amp; H400 + 16,&amp; H1,0)'暂停;绿色