0

我正在尝试更改自定义控件的进度条颜色。我尝试了很多方法,例如使用下面的发送消息功能:

<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 样式。

谢谢

4

3 回答 3

1

BackColor只是发送此消息。
正如文件所述,

启用视觉样式后,此消息无效。

你不能做这个。

于 2012-05-20T18:50:25.930 回答
1

在 CodeProject,http ://www.codeproject.com/Articles/9635/A-Smooth-ProgressBar-for-everyone-Part-Duex 上,Stumpy 创建了一个 SmoothProgressBar,允许您创建具有可变颜色的进度条。一探究竟。

于 2012-05-21T11:48:56.543 回答
0

感谢您的帮助,但我决定使用以下内容:

SendMessage(PercentFull.Handle, &H400 + 16, &H2, 0) '错误; 红色
SendMessage(PercentFull.Handle, &H400 + 16, &H3, 0) '暂停;黄色
SendMessage(PercentFull.Handle, &H400 + 16, &H1, 0) '暂停;绿色

于 2012-05-22T08:49:47.320 回答