Coding the form factory class

A class file will have been added for the project. Add the code for your form factory to this file. Begin by adding a namespace reference for the Microsoft.Dexterity.Shell namespace to make referencing methods in the assembly easier:

using Microsoft.Dexterity.Shell;

Next, specify that the new class inherits from the FormFactory class. You may want to change the name of the new class to better describe what form the form factory will be used with. For example, the following class defines the form factory for the About Box form in Microsoft Dynamics GP. Notice how it inherits from the FormFactory class that is defined in the Microsoft.Dexterity.Shell namespace.

public class AboutBoxFormFactory: FormFactory 
{

}

The code in this form factory class will run before the window is displayed in the application. To override the default window wrapper, you must override either the CreateDexForm method or the CreateDexDialogForm method in the form factory class. Which method you override will depend on the window type in Dexterity:

It’s important that you use the right method with the specific window type. If you don’t, the new form factory you are creating won’t work.


Parameters passed in to the method you are overriding allow you to control exactly which form/window combination will have its window wrapper altered. The code in the overridden method must return one of the following:

The following example shows the complete form factory class file for a form factory that adds controls to the About Box window in Microsoft Dynamics GP. Notice how the class inherits from the FormFactory class. It overrides the CreateDexForm method, since the About Box has the window type “Primary”. The code checks the product ID and form ID to verify that it’s the About Box from Microsoft Dynamics GP that’s being overridden. If it’s the correct form, a modified version of the wrapper is returned that contains the additional controls. Otherwise, the standard base wrapper is returned. The override for the CreateDexDialogForm method is also shown. This method would have been overridden if the window type was “ModalDialog”.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Dexterity.Shell;

namespace FormFactorySample
{
	public class AboutBoxFormFactory: FormFactory 
	{
		// Windows with type 'Primary'
		protected override DexForm CreateDexForm(string name, DexWindowType
		windowType, FormFlags flags, WindowState windowState, System.Drawing.Size
		minClientSize, System.Drawing.Size clientSize, bool hResizeable, 
		bool vResizeable, short productId, short formId, short windowId, 
		bool modified)
		{
			// Is the form the "About Box" with form ID value of 1?
			if ((productId == 0) && (formId == 1))
			{
				return new SampleForm(name, windowType, flags, windowState,
				minClientSize, clientSize, hResizeable, vResizeable, productId,
				formId, windowId, modified);
		}
			else
			{
				return base.CreateDexForm(name, windowType, flags, windowState,
				minClientSize, clientSize, hResizeable, vResizeable, productId,
				formId, windowId, modified);
		}
	}

		// Windows with type 'Modal Dialog'
		protected override DexDialogForm CreateDexDialogForm(string name,
		DexWindowType windowType, FormFlags flags, WindowState windowState,
		System.Drawing.Size minClientSize, short productId, short formId,
		short windowId, bool modified)
		{
			return base.CreateDexDialogForm(name, windowType, flags, windowState,
			minClientSize, productId, formId, windowId, modified);
	}
}
}


Documentation Feedback