/// <summary> /// 开关按钮 /// </summary> [ToolboxItem(true)] [DefaultProperty("Type")] [Description("开关按钮")] public partial class SwitchExt : Control { #region private SwitchType type = SwitchType.Flat; /// <summary> /// 按钮类型 /// </summary> [DefaultValue(SwitchType.Flat)] [Description("按钮类型")] public SwitchType Type { get { return this.type; } set { if (this.type == value) return; this.type = value; this.InitializeSwitchLayout(); this.Invalidate(); } } private int radius = 5; /// <summary> /// 按钮圆角大小(限于Flat) /// </summary> [DefaultValue(5)] [Description("按钮圆角大小(限于Flat)")] public int Radius { get { return this.radius; } set { if (this.radius == value) return; this.radius = value; if (this.Type == SwitchType.Flat) { this.InitializeSwitchLayout(); this.Invalidate(); } } } private Color backdropColor = Color.FromArgb(245, 165, 166); /// <summary> /// 背景颜色 /// </summary> [DefaultValue(typeof(Color), "245, 165, 166")] [Description("背景颜色")] [Editor(typeof(ColorEditorExt), typeof(System.Drawing.Design.UITypeEditor))] public Color BackdropColor { get { return this.backdropColor; } set { if (this.backdropColor == value) return; this.backdropColor = value; this.InitializeSwitchLayout(); this.Invalidate(); } } private Color backdropSelectColor = Color.FromArgb(167, 204, 233); /// <summary> /// 选中时背景颜色 /// </summary> [DefaultValue(typeof(Color), "167, 204, 233")] [Description("选中时背景颜色")] [Editor(typeof(ColorEditorExt), typeof(System.Drawing.Design.UITypeEditor))] public Color BackdropSelectColor { get { return this.backdropSelectColor; } set { if (this.backdropSelectColor == value) return; this.backdropSelectColor = value; this.InitializeSwitchLayout(); this.Invalidate(); } } private Color backdropBorderColor = Color.FromArgb(245, 165, 166); /// <summary> /// 背景边框颜色 /// </summary> [DefaultValue(typeof(Color), "245, 165, 166")] [Description("背景边框颜色")] [Editor(typeof(ColorEditorExt), typeof(System.Drawing.Design.UITypeEditor))] public Color BackdropBorderColor { get { return this.backdropBorderColor; } set { if (this.backdropBorderColor == value) return; this.backdropBorderColor = value; this.InitializeSwitchLayout(); this.Invalidate(); } } private int backdropBorderThickness = 0; /// <summary> /// 背景边框画笔大小 /// </summary> [DefaultValue(0)] [Description("背景边框画笔大小")] public int BackdropBorderThickness { get { return this.backdropBorderThickness; } set { if (this.backdropBorderThickness == value || value < 0) return; this.backdropBorderThickness = value; this.InitializeSwitchLayout(); this.Invalidate(); } } private Color slideColor = Color.FromArgb(255, 255, 255); /// <summary> /// 滑块颜色 /// </summary> [DefaultValue(typeof(Color), "255, 255, 255")] [Description("滑块颜色")] [Editor(typeof(ColorEditorExt), typeof(System.Drawing.Design.UITypeEditor))] public Color SlideColor { get { return this.slideColor; } set { if (this.slideColor == value) return; this.slideColor = value; this.InitializeSwitchLayout(); this.Invalidate(); } } private Color slideSelectColor = Color.FromArgb(255, 255, 255); /// <summary> /// 选中时滑块颜色 /// </summary> [DefaultValue(typeof(Color), "255, 255, 255")] [Description("选中时滑块颜色")] [Editor(typeof(ColorEditorExt), typeof(System.Drawing.Design.UITypeEditor))] public Color SlideSelectColor { get { return this.slideSelectColor; } set { if (this.slideSelectColor == value) return; this.slideSelectColor = value; this.InitializeSwitchLayout(); this.Invalidate(); } } private Color slideBorderColor = Color.FromArgb(255, 255, 255); /// <summary> /// 滑块边框颜色 /// </summary> [DefaultValue(typeof(Color), "255, 255, 255")] [Description("滑块边框颜色")] [Editor(typeof(ColorEditorExt), typeof(System.Drawing.Design.UITypeEditor))] public Color SlideBorderColor { get { return this.slideBorderColor; } set { if (this.slideBorderColor == value) return; this.slideBorderColor = value; this.InitializeSwitchLayout(); this.Invalidate(); } } private int slideBorderThickness = 0; /// <summary> /// 滑块边框画笔大小 ///
Switch开关按钮控件----------WinForm控件开发系列
最新推荐文章于 2024-05-16 14:00:43 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)