using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace laserPTZ { public partial class panelE : Control { private Color _BorderColor = Color.Red; [Browsable(true), Description("边框颜色"), Category("自定义分组")] public Color BorderColor { get { return _BorderColor; } set { _BorderColor = value; this.Invalidate(); } } private int _BorderSize = 3; [Browsable(true), Description("边框粗细"), Category("自定义分组")] public int BorderSize { get { return _BorderSize; } set { _BorderSize = value; this.Invalidate(); } } private const int WS_EX_TRANSPARENT = 0x00000020; protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle = cp.ExStyle | WS_EX_TRANSPARENT; return cp; } } protected Graphics graphics; /// <summary> /// 重写OnPaint方法 /// </summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { if (BackgroundImage != null) e.Graphics.DrawImage(this.BackgroundImage, new Point(0, 0)); /*this.graphics = e.Graphics; this.graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; this.graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear; this.graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; this.graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; this.graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; using (var brush = new SolidBrush(Color.FromArgb(0, 0, 0, 0))) { e.Graphics.FillRectangle(brush, this.ClientRectangle); } base.OnPaint(e);*/ ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, this._BorderColor, this._BorderSize, ButtonBorderStyle.Solid, this._BorderColor, this._BorderSize, ButtonBorderStyle.Solid, this._BorderColor, this._BorderSize, ButtonBorderStyle.Solid, this._BorderColor, this._BorderSize, ButtonBorderStyle.Solid); } public panelE() { //SetStyle(ControlStyles.Opaque, true); InitializeComponent(); } public panelE(IContainer container) { container.Add(this); //SetStyle(ControlStyles.Opaque, true); InitializeComponent(); } } }