How to add .Net controls in AX 2012 Forms.

Today I will demonstrate you that How to add .Net controls in AX 2012 forms.

1. Create a new form and add a new ManagedHost control as shown below.
2. From the control selectors, select System.Windows.Forms and Button control  and click on Ok Button
3. Then, Right click on the ManagedHost control and chose Events
4. From the list of events, select the click event and click on Add button as shown below
5. Once you do this, you will automatically find that in the ClassDeclaration the control object is created.

public class FormRun extends ObjectRun
{
    System.Windows.Forms.Button _ManagedHost_Control;

}

6.Also, init() method will have the following code with the eventHandler.
  • You use the properties of the .NET control to configure that control or to obtain information from the control. To set a property value, assign a value to the set_<property name> property of the .NET control. To retrieve a value from a .NET control, use the get_<property name> property of the .NET control. [msdn]
Init() method – code below

public void init()
{
    super();
    _ManagedHost_Control = ManagedHost.control();
    _ManagedHost_Control.add_Click(new ManagedEventHandler(this, ‘ManagedHost_Click’));

    _ManagedHost_Control.set_Text("Open customer table");
}

When the button is clicked, ManagedHost_Click method gets triggered and I am just opening the customer table in the clicked event

void ManagedHost_Click(System.Object sender, System.EventArgs e)
{
    ;
    new SysTableBrowser().run(tableNum(CustTable));
}

7. We are done, Now right click on the form and chose Open. You will see that .NET Button control is on your form with text “Open customer table” a shown below
8. Click on the button and you should see the custTable opening in the TableBrowser.



Comments