Hi, I try to load csharp code from *.cs and show it into Host.
I got information from assembly, but I can't get the view.
why my view is always null, but m_rootDesigner have value?
Assembly assember = newcompilered.CompiledAssembly;
//取得typelist
this.richTextBox1.Clear();
foreach(Module module in assember.GetModules())
{
foreach(Type type in module.GetTypes())
{
if(type.IsSubclassOf(typeof(Control)))
{
Control c = assember.CreateInstance(type.FullName) as Control;
if(c is Form)
{
IComponent compForm = c as IComponent;
//if I direct add line after, I can see it appear in other , but I
want to see it in the panel
// host.Container.Add(c,c.Name);
designer =
TypeDescriptor.CreateDesigner(compForm,typeof(IRootDesigner));
m_rootDesigner = (IRootDesigner) designer;
m_designers[c] = m_rootDesigner;
if(m_rootDesigner == null)
{
MessageBox.Show("Can't create root designer!");
}
if(view != null)
{
pnlViewHost.Controls.Clear();
view.Dispose();
}
//設定Component
foreach(Control subc in c.Controls)
{
IComponent comp = subc as IComponent;
designer = TypeDescriptor.CreateDesigner(comp,typeof(IDesigner));
if(designer != null)
{
designer.Initialize(comp);
m_designers[comp] = designer;
}
}
//View未轉完成
view =
(Control)m_rootDesigner.GetView(ViewTechnology.WindowsForms);
if(view == null)
{
MessageBox.Show("Can't create view!");
}
//view.Dock = DockStyle.Fill;
pnlViewHost.Controls.Add(view);
}
}
}
}
|