Visual Studio 的 PropertyGrid 是元件設計時配置屬性的核心介面。內建編輯器僅支援基本型別,若需針對特定領域型別(如角度、漸層色彩軌跡條)提供視覺化編輯體驗,必須實作 UITypeEditor。
核心介面實作:
GetEditStyle:回傳 DropDown 模式EditValue:透過 IWindowsFormsEditorService.DropDownControl 顯示自訂 AngleControl(UserControl),接收使用者拖曳/點選回傳的角度值PaintValue:在 PropertyGrid 值欄位直接繪製角度指示圖(紅線+圓心),支援設計時即時預覽功能豐富的數值編輯器,支援:
StartColor/EndColor)DarkenBy 屬性控制遮罩深度)OptimizedInvalidate 僅重繪數值變化區域與文字區域[Editor(typeof(AngleEditor), typeof(UITypeEditor))]
public double Angle { get; set; }
[Editor(typeof(FlashTrackBarValueEditor), typeof(UITypeEditor))]
public int Value { get; set; }
FlashTrackBarValueEditor 封裝共同邏輯:
SetEditorProps 讓衍生類客製化編輯器外觀/範圍ValueChanged 事件自動關閉下拉框衍生類 FlashTrackBarDarkenByEditor 僅需覆寫 SetEditorProps 設定 Min=0, Max=255 即可復用完整邏輯。
System.Diagnostics.Debugger.Launch() 在 EditValue 中觸發附加除錯器PermissionSet(SecurityAction.Demand, Name="FullTrust") 屬性,設計時編輯器需完全信任