DesignSurface设计组件界面加载控件

wubike 2006-04-03 08:38:59
surface = new DesignSurface();
Button control1 = new Button();

control1.Name = "control1";
control1.Text = "controlName";
control1.Top = 50;
control1.Left = 50;
control1.Height = 25;
control1.Width = 25;
control1.Visible = true;
control1.TabIndex = 1;
control1.BackColor = Color.Red;

//view.Container.Add(control1);
surface.ComponentContainer.Add(control1);

surface.BeginLoad(typeof(Form));


view = (Control)surface.View;
view.Dock = DockStyle.Fill;
view.Location = new Point(100, 100);
this..Panel1.Controls.Add(view);

运行时设计界面即view窗体能生成,但添加的确加的control1没有显示,是不是加载方法不对,请教各位,谢谢~
...全文
378 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wubike 2006-04-05
  • 打赏
  • 举报
回复
上面的代码好像还要转换一下,
IDesignerHost host = (IDesignerHost)surface.GetService(typeof(IDesignerHost));
Button1control1 = (Button1)host.CreateComponent(typeof(Button1), "Button1");

但还是没有显现出来
我还加了host.Container.Add(control1);
也没有显示


七伤拳 2006-04-05
  • 打赏
  • 举报
回复
surface = new DesignSurface();

IDesignerHost host = (IDesignerHost) surface.GetService(typeof(IDesignerHost));
Button control1 = host.CreateComponent(System.Windows.Forms.Button, "Button1");
七伤拳 2006-04-05
  • 打赏
  • 举报
回复
private void Form1_Load(object sender, EventArgs e)
{
DesignSurface surface = new DesignSurface();
surface.BeginLoad(typeof(Form));

Control designView = surface.View as Control;
this.Controls.Add(designView);
designView.Dock = DockStyle.Fill;
designView.Visible = true;

IDesignerHost host = (IDesignerHost)surface.GetService(typeof(IDesignerHost));
Control root = (Control) host.RootComponent;

Button button1 = (Button)host.CreateComponent(typeof(Button), "Button1");
button1.Text = "Button1";
button1.Location = new Point(50, 50);
button1.Size = new Size(60, 20);

root.Controls.Add(button1);
}
ice_frank 2006-04-04
  • 打赏
  • 举报
回复
关注
wubike 2006-04-04
  • 打赏
  • 举报
回复
up~
wubike 2006-04-04
  • 打赏
  • 举报
回复
~顶
wubike 2006-04-03
  • 打赏
  • 举报
回复
顶~

17,740

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧