2011-12-13 70 views
2

我派生了.NET UserControl,以创建自己的PictureList类。 但是,当我调整控件的父级时,控件的内容消失。没有Resize事件发布或其他。我遗漏了与问题无关的代码。当父级调整大小时,.NET自定义UserControl的内容正在消失

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); 
    } 
+0

我无法重现您的错误。我也不知道为什么地球上有一个在OnPaint中的MessageBox(希望只是为了抽象的目的)。您是以编程方式生成这些控件,还是与设计人员? – 2011-12-13 21:08:53

+0

我以编程方式创建它。 MessageBox仅用于解释目的。问题是,控制完美。我在设计器中使用它,将其放置在布局中,并将布局锚定到窗体的两侧。当我调整窗体大小时,图像就消失了。 – Supergrover 2011-12-13 21:14:46

回答

0

您是否需要启用AutoRedraw

相关问题