예제 #1
0
        /// <summary>
        /// Gets a new HostSurface and loads it with the appropriate type of
        /// root component.
        /// </summary>
        private HostControl GetNewHost(Type rootComponentType)
        {
            HostSurface hostSurface = (HostSurface)CreateDesignSurface(ServiceContainer);

            if (ReferenceEquals(rootComponentType, typeof(Form)))
            {
                hostSurface.BeginLoad(typeof(Form));
            }
            else if (ReferenceEquals(rootComponentType, typeof(UserControl)))
            {
                hostSurface.BeginLoad(typeof(UserControl));
            }
            else if (ReferenceEquals(rootComponentType, typeof(Component)))
            {
                hostSurface.BeginLoad(typeof(Component));
            }
            else if (ReferenceEquals(rootComponentType, typeof(MyTopLevelComponent)))
            {
                hostSurface.BeginLoad(typeof(MyTopLevelComponent));
            }
            else
            {
                throw new Exception("Undefined Host Type: " + rootComponentType.ToString());
            }

            hostSurface.Initialize();
            ActiveDesignSurface = hostSurface;
            return(new HostControl(hostSurface));
        }
예제 #2
0
        /// <summary>
        /// Opens an Xml file and loads it up using BasicHostLoader (inherits from
        /// BasicDesignerLoader)
        /// </summary>
        public HostControl GetNewHost(string fileName)
        {
            if (Equals(fileName, null) || !File.Exists(fileName))
            {
                MessageBox.Show("FileName is incorrect: " + fileName);
            }
            var loaderType = LoaderType.NoLoader;

            if (fileName.EndsWith("osm"))
            {
                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)CreateDesignSurface(ServiceContainer);
            IDesignerHost host        = (IDesignerHost)hostSurface.GetService(typeof(IDesignerHost));

            //
            var basicHostLoader = new Loader.BasicHostLoader(fileName);

            hostSurface.BeginLoad(basicHostLoader);
            hostSurface.Loader = basicHostLoader;

            hostSurface.Initialize();
            return(new HostControl(hostSurface));
        }
예제 #3
0
 internal HostControl(HostSurface hostSurface)
 {
     base.Load += HostControl_Load;
     // This call is required by the Windows.Forms Form Designer.
     InitializeComponent();
     InitializeHost(hostSurface);
 }
예제 #4
0
 internal void InitializeHost(HostSurface hostSurface)
 {
     try
     {
         if (hostSurface is null)
             return;
         _hostSurface = hostSurface;
         Control Control = _hostSurface.View as Control;
         Control.Parent = this;
         Control.Dock = DockStyle.Fill;
         Control.Visible = true;
         Control.ContextMenuStrip = ContextMenuStrip1;
        
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex.ToString());
     }
 }
예제 #5
0
        /// <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)CreateDesignSurface(ServiceContainer);
            IDesignerHost host        = (IDesignerHost)hostSurface.GetService(typeof(IDesignerHost));

            switch (loaderType)
            {
            case LoaderType.BasicDesignerLoader:
            {
                var basicHostLoader = new Loader.BasicHostLoader(rootComponentType);
                hostSurface.BeginLoad(basicHostLoader);
                hostSurface.Loader = basicHostLoader;

                break;
            }

            case LoaderType.CodeDomDesignerLoader:
            {
                var codeDomHostLoader = new Loader.CodeDomHostLoader();
                hostSurface.BeginLoad(codeDomHostLoader);
                hostSurface.Loader = codeDomHostLoader;
                break;
            }

            default:
            {
                throw new Exception("Loader is not defined: " + loaderType.ToString());
                break;
            }
            }

            hostSurface.Initialize();
            return(new HostControl(hostSurface));
        }