当我将此控件放在表单上时,更改它的大小和位置,保存并关闭表单。打开后,位置和大小都不一样了,但是在“.Designer.cs”中就是我这样设置的。我找不到这个问题的解决方案,甚至没有人提到它。
这是我正在使用的自定义控件的一个简单示例:
[Designer(typeof(myControlDesigner1))]
public partial class UserControl1 : UserControl
{
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[TypeConverter(typeof(Panel))]
[MergableProperty(false)]
public System.Windows.Forms.Panel Panel
{
get
{
return pnlWorkingArea;
}
set
{
pnlWorkingArea = value;
}
}
public UserControl1()
{
InitializeComponent();
}
}
public class myControlDesigner1 : ControlDesigner
{
public override void Initialize(IComponent component)
{
base.Initialize(component);
UserControl1 bc = component as UserControl1;
EnableDesignMode(bc.Panel, "MyPanel");
}
}