2012-05-20 537 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)「暫停;綠色