解决Winform背景图片闪烁的问题
2018-03-07 20:00
1556 查看
Winform窗体,里面放置了一个Panel,Dock属性为Fill,BackgroundImage使用一个本地图片文件,
BackgroundImageLayout使用了Stretch。嵌入图片的Panel作为Winform应用程序的背景,这个界面现在有两个问题:1、在窗体第一次被打开时,背景图片会出现明显的闪烁2、在拉动窗体的边界以调整窗体大小时,背景图片非出现明显的闪烁
解决方案:
需要新建一个PanelEnhanced类继承Panel类,代码如下:
C# Code:
/// <summary>
/// 加强版 Panel
/// </summary>
class PanelEnhanced : Panel
{
/// <summary>
/// OnPaintBackground 事件
/// </summary>
/// <param name="e"></param>
protected override void OnPaintBackground(PaintEventArgs e)
{
// 重载基类的背景擦除函数,
// 解决窗口刷新,放大,图像闪烁
return;
}
/// <summary>
/// OnPaint 事件
/// </summary>
/// <param name="e"></param>
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);
}
}
参考链接:http://www.csframework.com/ar
4000
chive/1/arc-1-20170622-2307.htm
www.csframework.com
BackgroundImageLayout使用了Stretch。嵌入图片的Panel作为Winform应用程序的背景,这个界面现在有两个问题:1、在窗体第一次被打开时,背景图片会出现明显的闪烁2、在拉动窗体的边界以调整窗体大小时,背景图片非出现明显的闪烁
解决方案:
需要新建一个PanelEnhanced类继承Panel类,代码如下:
C# Code:
/// <summary>
/// 加强版 Panel
/// </summary>
class PanelEnhanced : Panel
{
/// <summary>
/// OnPaintBackground 事件
/// </summary>
/// <param name="e"></param>
protected override void OnPaintBackground(PaintEventArgs e)
{
// 重载基类的背景擦除函数,
// 解决窗口刷新,放大,图像闪烁
return;
}
/// <summary>
/// OnPaint 事件
/// </summary>
/// <param name="e"></param>
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);
}
}
参考链接:http://www.csframework.com/ar
4000
chive/1/arc-1-20170622-2307.htm
www.csframework.com
相关文章推荐
- 使用DD_belatedPNG让IE6支持PNG透明图片 及IE6下背景图闪烁问题的解决方法
- 解决IE6下的CSS Hover背景图片闪烁问题
- 解决Winform应用程序中窗体背景闪烁的问题
- 有效解决WinForm窗体背景图片导致闪屏刷新问题
- 解决Winform应用程序中窗体背景闪烁的问题
- 解决Winform应用程序中窗体背景闪烁的问题
- c# 窗体的背景图片在加载时,背景图片闪烁问题 已解决
- 把view保存为图片的方法以及解决保存后图片背景变黑色的问题
- VS2010解决对话框设置背景图片和文字重叠问题
- (Winform)控件中添加GIF图片以及运用双缓冲使其不闪烁以及背景是gif时使控件(如panel)变透明
- 解决android:background背景图片被拉伸问题
- 解决vuejs项目里css引用背景图片不能显示的问题
- 解决android:background背景图片被拉伸问题
- 三行代码解决 winform 重绘闪烁,窗口重绘效率低下的问题
- 解决java压缩图片透明背景变黑色的问题
- android 解决按钮、imageView 背景图片拉伸变大的问题
- 【C#】 解决winform窗体闪烁问题
- 解决Android启动显示空白界面的问题,自定义进入软件前的背景图片。
- 解决 UIView 设置背景为UIImage图片变型问题[XXX setBackgroundColor:[UIColor colorWithPatternImage:XXX]];
- VS2010解决对话框设置背景图片和文字重叠问题