using DevExpress.XtraEditors; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace CompressorXN_ControlLib { public partial class PanelEx : PanelControl { public PanelEx() { InitializeComponent(); this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.DoubleBuffer, true); this.SetStyle(ControlStyles.ResizeRedraw, true); this.SetStyle(ControlStyles.Selectable, true); this.SetStyle(ControlStyles.SupportsTransparentBackColor, true); } private int topGap = 1; [Browsable(true)] [Category("自定义属性")] [Description("设置或显示上边间隔距离")] public int TopGap { get { return topGap; } set { topGap = value; this.Invalidate(); } } private int bottomGap = 1; [Browsable(true)] [Category("自定义属性")] [Description("设置或显示下边间隔距离")] public int BottomGap { get { return bottomGap; } set { bottomGap = value; this.Invalidate(); } } private int leftGap = 1; [Browsable(true)] [Category("自定义属性")] [Description("设置或显示左边间隔距离")] public int LeftGap { get { return leftGap; } set { leftGap = value; this.Invalidate(); } } private int rightGap = 1; [Browsable(true)] [Category("自定义属性")] [Description("设置或显示右边间隔距离")] public int RightGap { get { return rightGap; } set { rightGap = value; this.Invalidate(); } } private int borderWidth = 2; [Browsable(true)] [Category("自定义属性")] [Description("设置或显示边框宽度")] public int BorderWidth { get { return borderWidth; } set { borderWidth = value; this.Invalidate(); } } private Color borderColor = Color.FromArgb(35, 255, 253); [Browsable(true)] [Category("自定义属性")] [Description("设置或显示边框颜色")] public Color BorderColor { get { return borderColor; } set { borderColor = value; this.Invalidate(); } } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics graphics = e.Graphics; Pen pen = new Pen(borderColor,borderWidth); float x = leftGap + borderWidth * 0.5f; float y = TopGap + borderWidth * 0.5f; float width = this.Width - leftGap - rightGap - borderWidth; float height = this.Height - topGap - bottomGap - borderWidth; graphics.DrawRectangle(pen, x, y, width, height); } } }