2012-05-20 53 views
0

即时尝试更改自定义控件的进度栏的颜色。香港专业教育学院tryed不少methords像使用下面的sendingmessage功能:进度条更改颜色

<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 

,但对我来说这没有工作我couldent看到任何改变。

什么将是我改变这种控制的前景的最佳方式?我无法使用PercentFull.ForeColor,因为我将启用xp样式。

谢谢

+0

没有,但它是一个自定义的控制,所以我不必须禁用XP样式的选项。这个控制也可以用于XP机器。谢谢。 – Houlahan

回答

1

BackColor只是发送此消息。
作为文档状态,

当启用视觉样式,这条消息没有任何影响。

你不能这样做。

+0

@ user3026015:问题表明他希望启用视觉样式。 – SLaks

0

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

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