111,098
社区成员




using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace Gravity
{
[Designer(typeof(MyPanelDesigner))]
class MyPanel : Panel
{
public MyPanel()
{
Dock = DockStyle.Top;
BackColor = System.Drawing.Color.Red;
}
}
class MyPanelDesigner : ControlDesigner
{
public override void Initialize(IComponent component)
{
base.Initialize(component);
IDesignerHost ids = GetService(typeof(IDesignerHost)) as IDesignerHost;
Control c = this.Control; //当前被设计的组件 MyPanel
Control parent = ids.RootComponent as Control; //父窗体
MemberDescriptor aMem_Controls = TypeDescriptor.GetProperties(parent)["Controls"];
RaiseComponentChanging(aMem_Controls); //通知设计器 parent中的子控件发生变化
parent.Size = new System.Drawing.Size(parent.Width, parent.Height + c.Height); //父控件(窗体)高度增加
foreach (Control cc in parent.Controls) //改变父控件中每一个子控件位置
{
cc.Location = new System.Drawing.Point(cc.Location.X, cc.Location.Y + c.Height);
}
RaiseComponentChanged(aMem_Controls,null,null); //通知设计器 parent中子控件以及发生变化 设计器会自动生成代码
}
}
}