代码如下:重绘panel,并在新panel的构造函数中,设置双缓冲即可;
public partial class BackGroundPanel : Panel
{
public BackGroundPanel()
{
SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint
| ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw
| ControlStyles.SupportsTransparentBackColor, true);
//SetStyle(ControlStyles.
}
////SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
//protected override void OnPaintBackground(PaintEventArgs e)
//{
// //
// // 重载基类的背景擦除函数,
// // 解决窗口刷新,放大,图像闪烁
// // do nothing here: doesn't paint background => no flickering
// return;
//}
//protected override void OnPaint(PaintEventArgs e)
//{
// // render-code goes here
// this.DoubleBuffered = true;
// if (this.BackgroundImage != null)
// {
// e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
// // e.ClipRectangle
// 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);
//}
}同时,为了能够在测试容器中测试:
需要对designer.cs中的代码改动如下:
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
///
private void InitializeComponent()
{
this.panel_wholeFrameTrend = new BackGroundPanel();
}
BackGroundPanel panel_wholeFrameTrend;
//private void InitializeComponent()
//{
// components = new System.ComponentModel.Container();
// //this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
//}
#endregion
}
本文详细介绍了如何在Panel组件中实现双缓冲技术以避免图像闪烁问题,并通过调整设计时的代码来确保测试容器的有效运行。重点讨论了在Windows Forms应用程序中优化界面显示效果和测试流程的方法。
618

被折叠的 条评论
为什么被折叠?



