【问题标题】:Progress bar change colour进度条改变颜色
【发布时间】:2012-05-20 18:46:31
【问题描述】:

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

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

谢谢

【问题讨论】:

  • 否,但它用于自定义控件,所以我没有禁用 xp 样式的选项。此控件也可用于 xp 机器。谢谢。

标签: vb.net progress-bar


【解决方案1】:

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

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

你不能这样做。

【讨论】:

  • @user3026015:问题表明他希望启用视觉样式。
【解决方案2】:

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

【讨论】:

    【解决方案3】:

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

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

    【讨论】:

      猜你喜欢
      • 2011-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      相关资源
      最近更新 更多