#副標=Visual Studio 2005新功能系列(9) #大標=使用智慧標籤簡化視窗UI程式開發作業 #眉標=Visual Studio 2005 #作者=文/沈炳宏 ============Box 程式1============ _ Public Class ColorButton Inherits System.Windows.Forms.Button Private colorLockedValue As Boolean = False Public Property ColorLocked() As Boolean Get Return colorLockedValue End Get Set(ByVal value As Boolean) colorLockedValue = value End Set End Property Public Overrides Property BackColor() As Color Get Return MyBase.BackColor End Get Set(ByVal value As Color) If ColorLocked Then Return Else MyBase.BackColor = value End If End Set End Property Public Overrides Property ForeColor() As Color Get Return MyBase.ForeColor End Get Set(ByVal value As Color) If ColorLocked Then Return Else MyBase.ForeColor = value End If End Set End Property Public Overrides Property Font() As Font Get Return MyBase.Font End Get Set(ByVal value As Font) MyBase.Font = value End Set End Property End Class ===============end============= =============box程式2============ Public Class ColorButtonActionList Inherits System.ComponentModel.   Design.DesignerActionList Public Sub New(ByVal component   As IComponent)   … End Sub   Public Property BackColor() As Color … End Property Public Property ForeColor() As Color … End Property Public Property Font() As Font … End Property Public Property LockColors() As Boolean … End Property Public Property [Text]() As String … End Property Public Overrides Function   GetSortedActionItems() As   DesignerActionItemCollection … End Function ==============end============ ===========box 程式3=========== Public Property BackColor() As Color Get Return colButton.BackColor End Get Set(ByVal value As Color) GetPropertyByName("BackColor"). SetValue(colButton, value) End Set End Property Dim items As New DesignerActionItemCollection() items.Add(New DesignerActionPropertyItem( _ "BackColor", _ "背景色彩", _ "外觀", _ "選擇背景色彩.")) =============end=========== ===========box程式2========= Public Class ColorButtonDesigner Inherits System.Windows.Forms.   Design.ControlDesigner Private lists As DesignerActionListCollection Public Overrides ReadOnly Property ActionLists() _ As DesignerActionListCollection Get If lists Is Nothing Then lists = New DesignerActionListCollection() lists.Add( _ New ColorButtonActionList(Me.Component)) End If Return lists End Get End Property End Class ==============end========== ==============box程式3============ _ Public Image MyImage Get … End Get Set … End Set End Class 'MyImage ==================end=========== =========box 程式4========== Private colButton As ColorButton Public Sub InvertColors() Dim currentBackColor As Color = colButton.BackColor BackColor = Color.FromArgb( _ 255 - currentBackColor.R, _ 255 - currentBackColor.G, _ 255 - currentBackColor.B) Dim currentForeColor As Color = colButton.ForeColor ForeColor = Color.FromArgb( _ 255 - currentForeColor.R, _ 255 - currentForeColor.G, _ 255 - currentForeColor.B) End Sub items.Add( _ New DesignerActionMethodItem( _ Me, _ "InvertColors", _ "調換顏色", _ "外觀", _ "調換前景和背景色彩.", _ True)) ===============end============= ===========box 程式5================= items.Add( _ New DesignerActionPropertyItem( _ "BackColor", _ "背景色彩", _ GetCategory(this.Designer, " BackColor "), _ GetDescription(this.Designer, " BackColor ")) ==============end============== ==============box程式6============== items.Add(New DesignerActionPropertyItem( _ "BackColor", _ "背景色彩", _ "外觀", _ "選擇背景色彩.")) =================end================= ============box程式7============ Dim location As New StringBuilder("位置: ") location.Append(colButton.Location) Dim size As New StringBuilder("大小: ") size.Append(colButton.Size) items.Add(New DesignerActionHeaderItem("外觀")) items.Add(New DesignerActionHeaderItem("資訊")) items.Add( _ New DesignerActionTextItem( _ location.ToString(), _ "資訊")) items.Add( _ New DesignerActionTextItem( _ size.ToString(), _ "資訊")) =================end=============