2017-02-14 124 views
0

我正在爲我的應用程序的自定義設置工作。我創建了一個類,該類將所有設置保存爲要在屬性網格中顯示的公共屬性。使用自定義函數設置/讀寫數據庫。這一切都很適合我的需求。我有麻煩顯示顏色的方式,我認爲他們應該顯示在屬性網格中。即使對於已知顏色,屬性網格也只使用RGB值。爲什麼PropertyGrid控件中不顯示已知的顏色?

有沒有辦法讓屬性網格顯示已知的顏色,而不是RGB值?

這是我的設置類中的屬性。

<CategoryAttribute("Signature Capture"), _ 
    DescriptionAttribute("Sets the Pen color"), _ 
    DisplayName("PenColor"), _ 
    BrowsableAttribute(True), _ 
    ReadOnlyAttribute(False), _ 
    DefaultValueAttribute(GetType(Color), "Black"), _ 
    RefreshProperties(RefreshProperties.All)> _ 
    Public Property SignatureCapturePenColor() As Color 
     Get 
      Dim myset As New mySettings 
      Return Color.FromArgb(Convert.ToInt32(myset.GetSetting("SignatureCapturePenColor", mySettings.e_Scope.Tech))) 
     End Get 
     Set(ByVal value As Color) 
      Dim myset As New mySettings 
      myset.SetSetting("SignatureCapturePenColor", value.ToArgb, mySettings.e_Scope.Tech) 
      Dim ncSet As New ncSettings 
      ncSet.NotifyPropertyChanged() 
     End Set 
    End Property 

這是一個什麼樣的屬性網格看起來像一個例子:

Property Grid

這應該顯示爲「黑色」,而不是「0,0,0」。

這甚至可能嗎?

我可以發佈更多的代碼或解釋更多,如果需要。這是我的第一個問題,所以請去容易對我...

回答

1

您正在使用ARGB值來存儲和返回所以它「認爲」您要自定義顏色的顏色。

使用和保存顏色的名稱,而不是..

Public Property SignatureCapturePenColor() As Color 
    Get 
     Dim myset As New mySettings 
     Return Color.FromName(myset.GetSetting("SignatureCapturePenColorName", mySettings.e_Scope.Tech)) 
    End Get 
    Set(ByVal value As Color) 
     Dim myset As New mySettings 
     myset.SetSetting("SignatureCapturePenColorName", value.Name, mySettings.e_Scope.Tech) 
     Dim ncSet As New ncSettings 
     ncSet.NotifyPropertyChanged() 
    End Set 
End Property 
+0

感謝您的非常快的響應!我多次嘗試過這種相同的技術,無法使其正確工作。我的問題是Setter沒有設置value.name。 – Nathan

+0

不知道你的設置集合,所以不能說。我只能告訴你,當你只保存並從變量中檢索名字時,屬性網格按預期工作。 –

相關問題