您的位置:首页 > 编程语言 > C#

c# 自定义控件 属性菜单 控件移动 闪烁

2014-10-23 14:07 330 查看
      开发了一个自定义的Tree控件,但是放到大窗体上时,每个控件的移动效果特别明显,客户体验非常差。后来知道是因为图片重绘 的问题。附上解决的代码

      public class BackgroundPanel : Panel 

        { 

            protected override void OnPaintBackground(PaintEventArgs e) 

            {

                return; 

            }

            

            protected override void OnPaint(PaintEventArgs e)

            {

                

                this.DoubleBuffered = true;

                if (this.BackgroundImage != null)

                {

                    e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                    e.Graphics.DrawImage(this.BackgroundImage, new System.Drawing.Rectangle(0, 0, this.Width, this.Height),

                        0, 0, this.BackgroundImage.Width, this.BackgroundImage.Height,

                        System.Drawing.GraphicsUnit.Pixel);

                }

                base.OnPaint(e);

            }

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  winform 重绘 闪烁 pane