Well, getting back on track with our series, today I will show you how to add the toolbar and status bar button controls in addition to adding the code that will allow our WinForm to be displayed as an menu option under the Additional menu on the Customer Maintenance window.
1) In the Toolbox window, choose Button
2) Click on the toolbar area of the window to place the button control. Then change the properties as indicated in the picture below:
Note that the ButtonType on dexButtonProvider property is implemented as part of the Microsoft Dexterity Shell assembly (Microsoft.Dexterity.Shell.dll). Also, note that when I set the value to ToolbarWithSeparator the button immediately acquired the “look and field” of a typical Dexterity toolbar button.
3) Now, let’s add the image to the Ok button. To do this, we can click on the image property and select the picture resource that best suit our needs:
In this case, I selected the Toolbar_Post image in the Resources file. Now, you can choose to add the actual checkmark image as part of the existing resources, but that is not a topic of this article.
4) On your own, add the window help button and the window note present and window note absent buttons to the status bar. For these controls, you will want to change the ButtonType on dexButtonProvider property to StatusArea and remove clear the text in the Text property. Don’t forget to stack the the note buttons! The final result should look like the picture below:
5) Now that we have finalized the window layout, let’s add some code to create the equivalent of a Dexterity form trigger. This will create an Additional menu on the Customer Maintenance window, allowing us to open the form. In VST, Dexterity form triggers are known as Menu Handler events and need to be registered in the Initialize() method in the GPAddIn.cs class.
A couple things to note. In this script, we added static references to the Customer Maintenance form and rmCustomerHobbies WinForm to facilitate interacting with these throughout our code:
We also added the menu handler event to assist in displaying a menu option to call our WinForm from the Customer Maintenance window. The OpenRMCustomerHobbies event handler method is the equivalent of a trigger processing procedure in Dexterity:
In Dexterity, the open form statement does a few things: it opens the form, activates the form, and open the main window of that form, if the AutoOpen property of the window is set to True . In VST, we can accomplish the same in two steps, by invoking the Show() and Activate() class methods of the form object.
With the instructions provided in Part 1 of the WinForms and Controls series, we can proceed to build and deploy our assembly (I did not change the assembly name for this project). Once you load GP, open the Customer Maintenance window (Cards > Sales > Customer) to test the solution. You should now see the Additional menu option, along with our Customer Hobbies entry.
If you select the option, you should now see our form. Granted, we haven’t added any code to manage whether a record was selected or not prior to our form being opened, we did not add any code to preset the Customer ID and Customer Name fields on our WinForm based on the same field values on the Customer Maintenance window, and certainly have not added any code to retrieve or store data based on the selected customer. All this will be a part of our next article.
GPWinForm solution – C# – Click here
Getting Started with VST: WinForms and Controls – Part 1
Getting started with VST: “Hello World!” – The Video
Getting started with VST: “Hello World!” project
Getting started with Visual Studio Tools for Microsoft Dynamics GP — Adventures of a Microsoft Dexterity developer
Until next post!
Mariano Gomez, MVP
Maximum Global Business, LLC