Forum  Core :: SDK (Vi...   How do I...?  Using IFormFactory
Previous Previous
 
Next Next
New Post 10/29/2009 2:47 PM
  shan1000
6 posts
No Ranking


Using IFormFactory 

Hi

I want to load Form1.cs dynamically, and here is what I have

I have the following code in test.cs and Form1.cs in my solution.

using System;
using System.Data;
using System.Configuration;
using Gizmox.WebGUI.Common.Configuration;
using System.IO;
using System.Xml;
using Gizmox.WebGUI.Common.Interfaces;
using Gizmox.WebGUI.Forms;
using System.Reflection;

/// <summary>
/// Catalog module form router
/// </summary>

namespace LoginTest
{
    [Serializable()]
    public class CatalogModuleRouter : IFormFactory
    {

        #region ModuleForm class

        /// <summary>
        /// The actual form that will be displayed
        /// </summary>

        [Serializable()]
        private class ModuleForm : Form
        {
            /// <summary>
            /// The current hosted application
            /// </summary>
            //private IHostedApplication mobjCurrentHostedApplication = null;

            /// <summary>
            /// The current toolbar
            /// </summary>
            //private ToolBar mobjToolBar = null;

            /// <summary>
            /// Initializes a new instance of the <see cref="ModuleForm"/> class.
            /// </summary>
            /// <param name="objModule">The module control.</param>
            public ModuleForm(Control objModuleControl)
            {
                // Add module contlrol
                objModuleControl.Dock = DockStyle.Fill;
                this.Controls.Add(objModuleControl);

                // Create toolbar if is hosted application
                //mobjCurrentHostedApplication = objModuleControl as IHostedApplication;
                //if (mobjCurrentHostedApplication != null)
                //{
                //    mobjToolBar = new ToolBar();
                //    mobjToolBar.Dock = DockStyle.Top;
                //    this.Controls.Add(mobjToolBar);
                //    CatalogSettings.InitializeCatalogModule(mobjCurrentHostedApplication, mobjToolBar, new EventHandler(ToolBarButton_Click));
                //}


            }

            /// <summary>
            /// Handles the Click event of the ToolBarButton control.
            /// </summary>
            /// <param name="sender">The source of the event.</param>
            /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
            //private void ToolBarButton_Click(object sender, EventArgs e)
            //{
            //    if (mobjCurrentHostedApplication != null)
            //    {
            //        CatalogSettings.HandleApplicationHostToolBarClick(mobjCurrentHostedApplication, this.mobjToolBar, (ToolBarButton)sender, e);
            //    }
            //}
        }

        #endregion

        #region IFormFactory Members

        /// <summary>
        /// Creates the application main form.
        /// </summary>
        /// <param name="strCurrentPage">The current page code.</param>
        /// <param name="arrArguments">The application arguments.</param>
        /// <returns>
        /// A form object that will be the main form of the application.
        /// </returns>
        public IForm CreateForm(string strCurrentPage, params object[] arrArguments)
        {
            // Get the current context
            IContext objContext = VWGContext.Current;

            // The module to be dislayed
            Type objModuleType = null;

            // The module control to be displayed
            Control objModuleControl = null;

            // Check valid context and arguments
            if (objContext != null && objContext.Arguments != null)
            {
                // Get module type
                ////string strModuleName = (string)objContext.Arguments["module"];
                //if (strModuleName != null)
                //{
                //    objModuleType = CatalogSettings.GetCatalogModuleTypeByModuleName(strModuleName);
                //}
            }

            Assembly a = Assembly.GetExecutingAssembly();
            Type t = a.GetType("Form1");

            // Check for valid control
            if (objModuleType == null)
            {
                objModuleType = typeof(UserControl);
            }

            // Create module control
            objModuleControl = (Control)Activator.CreateInstance(objModuleType);

            // Return a new module form
            return new ModuleForm(objModuleControl);
        }

        #endregion
    }
}

 

ANd in Web.config file

        <Applications>
            <Application Code="ModuleForm" Type="LoginTest.CatalogModuleRouter, LoginTest"/>
        </Applications>
 

 

Project Property - Web Tab, I set "ModuleForm.wgx " as specific page,

Am i missing anything.

Please help.

Shan.

 
New Post 11/7/2009 1:27 PM
  palli
11189 posts
1st Level Poster




Re: Using IFormFactory 

Hi Shan,

Apart from the fact that your code is creating an empty Form and placing an empty UserControl on it, then I don't see anything missing. Adding this code right after creating the module control will show a Form with the UserControl containing that Checkbox:

 

CheckBox c = new CheckBox() ;
c.Text  = "test";
objModuleControl.Controls.Add(c);

Hope this helps,

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
Previous Previous
 
Next Next
  Forum  Core :: SDK (Vi...   How do I...?  Using IFormFactory
CompanionKit Bottom
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS