panel若添加透明背景图,panel上的控件刚显示时太卡

qq_16031013 2019-03-11 10:38:36
Form背景色为24,28,29,Form上有几个panel,每个panel都有很多控件label和textbox,panel背景色设为透明,当panel没有使用背景图时(即backgroundimage属性为无),所有控件可以一下子显示出来;但当使用透明的背景图片时(设置backgroundimage属性为本地某个透明的PNG图片),控件就一个接一个慢慢显示出来的,卡的很,请问该如何解决?
...全文
229 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_16031013 2019-03-13
  • 打赏
  • 举报
回复
引用 1 楼 desperaso 的回复:

/// <summary>
/// 双缓冲 panel
/// </summary>
public class PanelEx : Panel
{
public PanelEx()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
UpdateStyles();
}
}

/// <summary>
/// 双缓冲 PictureBox
/// </summary>
public class PictureBoxEx : PictureBox
{
public PictureBoxEx()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
UpdateStyles();
}
}

/// <summary>
/// 双缓冲 TreeView
/// </summary>
public class TreeViewEx : TreeView
{
protected override void OnHandleCreated(EventArgs e)
{
SendMessage(this.Handle, TVM_SETEXTENDEDSTYLE, (IntPtr)TVS_EX_DOUBLEBUFFER, (IntPtr)TVS_EX_DOUBLEBUFFER);
base.OnHandleCreated(e);
}
private const int TVM_SETEXTENDEDSTYLE = 0x1100 + 44;
private const int TVM_GETEXTENDEDSTYLE = 0x1100 + 45;
private const int TVS_EX_DOUBLEBUFFER = 0x0004;
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
}

/// <summary>
/// 双缓冲 ListView
/// </summary>
public class ListViewEx : ListView
{
public ListViewEx()
{
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
UpdateStyles();
}
}



请问只要写下面关于panel的就可以了,panel上的控件不用写了吧,是写在Form1.cs中对吧
public class PanelEx : Panel
{
public PanelEx()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
UpdateStyles();
}
}
desperaso 2019-03-12
  • 打赏
  • 举报
回复

/// <summary>
/// 双缓冲 panel
/// </summary>
public class PanelEx : Panel
{
public PanelEx()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
UpdateStyles();
}
}

/// <summary>
/// 双缓冲 PictureBox
/// </summary>
public class PictureBoxEx : PictureBox
{
public PictureBoxEx()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
UpdateStyles();
}
}

/// <summary>
/// 双缓冲 TreeView
/// </summary>
public class TreeViewEx : TreeView
{
protected override void OnHandleCreated(EventArgs e)
{
SendMessage(this.Handle, TVM_SETEXTENDEDSTYLE, (IntPtr)TVS_EX_DOUBLEBUFFER, (IntPtr)TVS_EX_DOUBLEBUFFER);
base.OnHandleCreated(e);
}
private const int TVM_SETEXTENDEDSTYLE = 0x1100 + 44;
private const int TVM_GETEXTENDEDSTYLE = 0x1100 + 45;
private const int TVS_EX_DOUBLEBUFFER = 0x0004;
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
}

/// <summary>
/// 双缓冲 ListView
/// </summary>
public class ListViewEx : ListView
{
public ListViewEx()
{
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
UpdateStyles();
}
}

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧