. net自定义UserControl'的内容会在父控件调整大小时消失
本文关键字:控件 调整 消失 小时 UserControl 自定义 net | 更新日期: 2023-09-27 18:17:50
我已经派生了。net UserControl,来创建我自己的PictureList类。但是,当我调整控件的父控件的大小时,控件的内容就消失了。没有发出Resize事件之类的。我省略了与问题无关的代码。
public ImageList(int width, int height)
{
ClientSize = new Size(width, height);
ResizeRedraw = true;
}
// Ensure background transparency will be handled corretly.
protected override CreateParams CreateParams
{
get {
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x20; // WS_EX_TRANSPARENT
return cp;
}
}
protected override void OnPaint(PaintEventArgs e)
{
MessageBox.Show("This messagebox is only shown upon the first drawing, but not after the magically disappearing of the contents");
img = /*the image to draw*/
rect = /*the size of the image*/
e.Graphics.DrawImage(img, rect);
}
是否需要启用AutoRedraw