2014-03-02 130 views
1

我對編程非常陌生,很快我將創建一個程序並希望通過單擊按鈕更改所選行的顏色。更改列表框/列表視圖中所選項目的顏色

我一直在嘗試這個,但我甚至不知道從哪裏開始。如果有人能指出我正確的方向,將不勝感激。

謝謝^。^

+1

我會指出你在正確的方向:[System.Windows.Controls](http://msdn.microsoft.com/en-us/library/System.Windows.Controls(v = vs.110).aspx )或[System.Windows.Forms的](http://msdn.microsoft.com/en-us/library/System.Windows.Forms(v = vs.110)的.aspx) –

+0

創建自定義之一,默認爲從系統繼承,因此爲什麼它可能是藍色的。 – Codexer

回答

0

你可以簡單地創建一個新的控件,然後更改設計師從列表框控件繼承。

設計的代碼會再看看這樣的事情(VS2010):

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ 
Partial Class UserControl1 
    Inherits ListBox 

    'UserControl overrides dispose to clean up the component list. 
    <System.Diagnostics.DebuggerNonUserCode()> _ 
    Protected Overrides Sub Dispose(ByVal disposing As Boolean) 
     Try 
      If disposing AndAlso components IsNot Nothing Then 
       components.Dispose() 
      End If 
     Finally 
      MyBase.Dispose(disposing) 
     End Try 
    End Sub 

    'Required by the Windows Form Designer 
    Private components As System.ComponentModel.IContainer 

    'NOTE: The following procedure is required by the Windows Form Designer 
    'It can be modified using the Windows Form Designer. 
    'Do not modify it using the code editor. 
    <System.Diagnostics.DebuggerStepThrough()> _ 
    Private Sub InitializeComponent() 
     components = New System.ComponentModel.Container() 
    End Sub 

End Class 

要看到設計師的代碼,選擇「顯示所有文件」(在您的解決方案資源管理器的頂部按鈕)。然後在解決方案資源管理器中展開新的控制節點。

然後換行:

Inherits System.Windows.Forms.UserControl 

到:

Inherits ListBox 

,最後刪除刪除該行:

Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font 

希望有所幫助。

相關問題