/// <summary> /// Gets a new HostSurface and loads it with the appropriate type of /// root component. Uses the appropriate Loader to load the HostSurface. /// </summary> public HostControl GetNewHost(Type rootComponentType, LoaderType loaderType) { if (loaderType == LoaderType.NoLoader) { return(GetNewHost(rootComponentType)); } HostSurface hostSurface = (HostSurface)this.CreateDesignSurface(this.ServiceContainer); IDesignerHost host = (IDesignerHost)hostSurface.GetService(typeof(IDesignerHost)); switch (loaderType) { case LoaderType.BasicDesignerLoader: BasicHostLoader basicHostLoader = new BasicHostLoader(rootComponentType); hostSurface.BeginLoad(basicHostLoader); hostSurface.Loader = basicHostLoader; break; case LoaderType.CodeDomDesignerLoader: CodeDomHostLoader codeDomHostLoader = new CodeDomHostLoader(); hostSurface.BeginLoad(codeDomHostLoader); hostSurface.Loader = codeDomHostLoader; break; default: throw new Exception("Loader is not defined: " + loaderType.ToString()); } hostSurface.Initialize(); return(new HostControl(hostSurface)); }
internal void InitializeHost(HostSurface hostSurface) { try { if (hostSurface == null) { return; } _hostSurface = hostSurface; // todo:qiuleilei 20161213 if (CurrentPrjInfo.CurrentEnvironment == MESEnvironment.MESReportServer) { return; } Control control = _hostSurface.View as Control; control.Parent = this; control.Dock = DockStyle.Fill; control.Visible = true; control.Invalidate(); control.Refresh(); //TextBox tb = new TextBox(); //tb.BackColor = Color.Pink; //tb.Location = new Point(100, 100); //control.Controls[0].Controls.Add(tb); //tb.BringToFront(); } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } }
/// <summary> /// Gets a new HostSurface and loads it with the appropriate type of /// root component. /// </summary> private HostControl GetNewHost(Type rootComponentType) { HostSurface hostSurface = (HostSurface)this.CreateDesignSurface(this.ServiceContainer); if (rootComponentType == typeof(Form)) { hostSurface.BeginLoad(typeof(Form)); } else if (rootComponentType == typeof(UserControl)) { hostSurface.BeginLoad(typeof(UserControl)); } else if (rootComponentType == typeof(Component)) { hostSurface.BeginLoad(typeof(Component)); } else if (rootComponentType == typeof(MyTopLevelComponent)) { hostSurface.BeginLoad(typeof(MyTopLevelComponent)); } else { throw new Exception("Undefined Host Type: " + rootComponentType.ToString()); } hostSurface.Initialize(); this.ActiveDesignSurface = hostSurface; return(new HostControl(hostSurface)); }
/// <summary> /// Opens an Xml file and loads it up using BasicHostLoader (inherits from /// BasicDesignerLoader) /// </summary> public HostControl GetNewHost(string fileName) { if (fileName == null || !File.Exists(fileName)) { MessageBox.Show("FileName is incorrect: " + fileName); } LoaderType loaderType = LoaderType.NoLoader; if (fileName.EndsWith("xml")) { loaderType = LoaderType.BasicDesignerLoader; } if (loaderType == LoaderType.NoLoader || loaderType == LoaderType.CodeDomDesignerLoader) { throw new Exception("File cannot be opened. Please check the type or extension of the file. Supported format is Xml"); } HostSurface hostSurface = (HostSurface)this.CreateDesignSurface(this.ServiceContainer); IDesignerHost host = (IDesignerHost)hostSurface.GetService(typeof(IDesignerHost)); BasicHostLoader basicHostLoader = new BasicHostLoader(fileName); hostSurface.BeginLoad(basicHostLoader); hostSurface.Loader = basicHostLoader; hostSurface.Initialize(); return(new HostControl(hostSurface)); }
//运行环境载入项目文件时调用的函数 public HostControl LoadNewHost(string fileName) { if (fileName == null || !File.Exists(fileName)) { MessageBox.Show("文件名不正确: " + fileName); } LoaderType loaderType = LoaderType.NoLoader; if (fileName.EndsWith("xml")) { loaderType = LoaderType.BasicDesignerLoader; } if (loaderType == LoaderType.NoLoader || loaderType == LoaderType.CodeDomDesignerLoader) { throw new Exception("文件打不开,请确认后缀名是xml!"); } HostSurface hostSurface = (HostSurface)this.CreateDesignSurface(this.ServiceContainer); IDesignerHost host = (IDesignerHost)hostSurface.GetService(typeof(IDesignerHost)); basicHostLoader = new BasicHostLoader(fileName, true); hostSurface.BeginLoad(basicHostLoader); hostSurface.Loader = basicHostLoader; hostSurface.Initialize(); return(new HostControl(hostSurface)); }
public DesignerControl(string strXml, string strFilepath, int justflag) { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); //_hostSurface = new HostSurface(strXml, strFilepath, 1); HostSurface hostSurface = new HostSurface(strXml, strFilepath, 1); InitializeHost(hostSurface); }
public DesignerControl() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); //_hostSurface = new HostSurface(); HostSurface hostSurface = new HostSurface(); InitializeHost(hostSurface); }
public DesignerControl(string strFilePath, bool UseAloneOnly) { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); //_hostSurface = new HostSurface(strFilePath, UseAloneOnly); HostSurface hostSurface = new HostSurface(strFilePath, UseAloneOnly); InitializeHost(hostSurface); }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } if (_hostSurface != null) { _hostSurface.Dispose(); _hostSurface = null; } } base.Dispose(disposing); }
internal void InitializeHost(HostSurface hostSurface) { try { if (hostSurface == null) { return; } _hostSurface = hostSurface; Control control = _hostSurface.View as Control; control.Parent = this; control.Dock = DockStyle.Fill; control.Visible = true; } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } }
public HostControl(HostSurface hostSurface) { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); InitializeHost(hostSurface); }