在ParentChanged事件上调整UserControl的大小

时间:2014-04-01 15:02:00

标签: c# winforms

我有一个Windows窗体UserControl我希望在它添加到窗体时调整大小(在设计时),在调试时,我看到由于某些原因,Visual Studio设计器在ParentChanged事件之后生成了一个额外的OnResize事件size(200x100),我希望我在ParentChanged事件上设置的大小保持不变,是否有解决方法?

//Sample class that reproduces the error, this usercontrol appears as a 200x100 
//control when added to a windows forms designer rather than 1024x768
public partial class TestUserControl : UserControl
{
    public TestUserControl()
    {
        InitializeComponent();
    }

    protected override void OnParentChanged(EventArgs e)
    {
        this.Size = new Size(1024, 768);
        base.OnParentChanged(e);
    }
}

0 个答案:

没有答案
相关问题