C# TableLayoutPanel 绘制边框,防闪屏

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;

namespace HSkin.Controls
{
    public class HSkinTableLayoutPanel : TableLayoutPanel
    {
        public HSkinTableLayoutPanel()
        {
            // 防止闪屏
            this.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(this, true, null);
        }


        private Color borderColor = Color.Black;


        public Color BorderColor
        {
            get { return borderColor; }
            set { borderColor = value; }
        }
   
        protected override void  OnCellPaint(TableLayoutCellPaintEventArgs e)
        { 
            //绘制边框
            base.OnCellPaint(e);
            Pen pp = new Pen(BorderColor);
            e.Graphics.DrawRectangle(pp, e.CellBounds.X, e.CellBounds.Y, e.CellBounds.X + this.Width - 1, e.CellBounds.Y + this.Height - 1);
        
        }
    }
}


C# TableLayoutPanel 绘制边框,防闪屏_第1张图片


你可能感兴趣的:(C#自定义控件,C#,开发总结)