| S2Container.NET TOP page # WindowsForm Page Flow Control This page explain on S2Windows.NET WindowsForm Page Flow Control. Usually to control page flow, object is created within a WindowsForm method. Following are steps necessary to use WindowsForm and page flow with DI: Setting up Page Flow Control Interface Readying executable class Editing a dicon file To use S2Windows.NET, set assembly (Seasar.Windows) at <assemblys> in the application configuration file. ## Setting up Page Flow Control Interface Add an interface to the project which contains the executable file. Add method that calls WindowsForm. Naming this method based on the convention will make dicon file setting easier. Use Seasar.Windows.Attr.TargetForm attribute to set form to a method. ID is just an example of a argument. Value of the argument is set to the form ID property. In other words, define a property on the form with the same name as the argument so the value will be set. Datatype of the return value will be either void or DialogResult. C#
    public interface IFormDispatcher
    {
        [TargetForm(typeof ( FrmHoge ), ModalType.Modal)]
        void ShowHoge(int ID);
    }
VB.NET
    Public Interface IFormDispatcher
        <TargetForm(GetType(FrmHoge), ModalType.Modal)> Sub ShowHoge(ByVal ID As Integer)
    End Interface
The first argument to the TargetForm attribute is the type of WindowsForm to move to. The second argument is the modal type of the WindowsForm. ## Readying executable class Set the project of the executable file to the application execution class. This can be done by moving the Main statement from the default form created when the project is created. Project startup object should, also, be changed to this executable class. C#
    public class StartMain
    {
        /// <summary>
        /// DI container configuration file
        /// </summary>
        private const string PATH = "Examples.dicon";

        /// <summary>
        /// constructor
        /// </summary>
        public StartMain()
        {
            ;
        }

        /// <summary>
        /// main entry point of an application
        /// </summary>
        [STAThread]
        private static void Main()
        {
            Application.EnableVisualStyles();

            IS2Container container = S2ContainerFactory.Create(PATH);
            container.Init();

            ApplicationContext context
                 = (ApplicationContext) container.GetComponent(typeof ( S2ApplicationContext ));
            Application.Run(context);
        }
    }
## Editing dicon File Set WindowsForm, ApplicationContext setting, and page flow control in the dicon file. WindowsForm is set as follows:
        <component name="frmHoge" class="Seasar.Windows.Examples.FrmHoge" />
To set WindowsForm to be Modaless, set instance attribute of the WindowsForm to "prototype". Otherwise, the window can not be reopened once the WindowsForm is closed. ApplicationContext setting in executable class is set as follows:
        <component name="AppContext" class="Seasar.Windows.S2ApplicationContext" >
           <arg>container</arg>
           <!-- change MainForm to initial startup form -->
           <property name="MainForm">frmHoge</property>
        </component>
Page flow control is set using AOP as follows. Set pointcut to Seasar.Windows.AOP.Interceptors.FormInterceptor of the page flow interface method.
        <component name="Dispatcher" class="Seasar.Windows.Examples.IFormDispatcher">
            <!-- display regular expression method name conforming to pointcut naming convention -->
            <aspect pointcut="Show.*">
                <component class="Seasar.Windows.AOP.Interceptors.FormInterceptor" />
            </aspect>
        </component>
Separate the WindowsForm dicon file from the Dao S2Unit.NET dicon file so WindowsForm objects will not be created during tests with S2Unit.NET. ## WindowsForm Utility Class Several utility classes are available for WindowsForm. They may be used to check inputs. Seasar.Windows.Util.Validator -- input check utility class .NET 1.1 also supports the following class: Seasar.Windows.Util.Converter -- conversion utility class |
Trans. by H.Ozawa | Copyright© 2004-2007, The Seasar Foundation and the others. All rights reserved.