programming4us
programming4us
ENTERPRISE

Microsoft Dynamics AX 2009 : Building Lookups - Choosing a font

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
12/2/2012 6:34:13 PM
The Dynamics AX Options from Tools menu allows users to define their preferred fonts and sizes for various application areas. In custom functionality, it might also be necessary to add similar options allowing configuring font properties.

In this recipe, we will add an option to select a font in the Form setup form in the Accounts receivable module for sales invoice layout. The code in this recipe could be used in conjunction with the code that reads this parameter and actually changes invoice font.

How to do it...

  1. 1. Open the CustFormLetterParameters table in AOT.

  2. 2. Add a new field:

    Property Value
    Type String
    Name InvoiceFontName
    ExtendedDataType FontName

  1. 3. Add one more field:

    Property Value
    Type Integer
    Name InvoiceFontSize
    ExtendedDataType FontSize

  1. 4. Open the CustFormLetterParameters form in AOT, and add a new display method to the CustFormLetterParameters data source:

    display Name displayInvoiceFont(
    CustFormLetterParameters _custFormLetterParameters)
    
    {;
    if (CustFormLetterParameters.InvoiceFontName)
    {
    return strfmt(
    "%1, %2",
    _custFormLetterParameters.InvoiceFontName,
    _custFormLetterParameters.InvoiceFontSize);
    }
    return "";
    }
    
  2. 5. Add a new group to the Invoice tab page right after the GroupInvoice group:

    Property Value
    Name GroupFont
    Caption Font
    Columns 2
    Columnspace 0

  1. 6. Add a StringEdit control to the newly created group:

    Property Value
    Name InvoiceFont
    AutoDeclaration Yes
    Label Font name & size
    DataSource CustFormLetterParameters
    DataMethod displayInvoiceFont

  1. 7. Add a new Button to the same group:

    Property Value
    Name InvoiceFontLookup
    ButtonDisplay Image only
    NormalResource 2633

  1. 8. Override clicked() on the InvoiceFontLookup button with the following code:

    void clicked()
    
    {
    container font;
    ;
    font = WinAPI::chooseFont(
    element.hWnd(),
    SysFontType::ScreenFont,
    CustFormLetterParameters.InvoiceFontName,
    CustFormLetterParameters.invoiceFontSize);
    if (conlen(font))
    {
    CustFormLetterParameters.InvoiceFontName =
    conpeek(font,1);
    CustFormLetterParameters.InvoiceFontSize =
    conpeek(font,2);
    InvoiceFont.update();
    }
    }
    
  2. 9. Here is how it looks in AOT after all the modifications have been done:

  1. 10. To test the results, open Accounts receivable | Setup | Forms | Form Setup, and click on the Font lookup button on the Invoice tab page:

  1. 11. Upon its closure, the lookup fills in the Font name & size field with the selected values:

How it works...

First, we create two new fields in the CustFormLetterParameters table for storing font name and size. We use standard FontName and FontSize extended data types to make sure that the fields inherit the correct properties.

Next, we modify the CustFormLetterParameters form. We will be adding the Font name & size control, which is bound to the display method displayInvoiceFont(). The method resides on the CustFormLetterParameters form data source and is responsible for displaying font name and size in one line separated by a comma. In this way, we save some form layout space instead of displaying font name and size in separate fields.

Dynamics AX does not have a standard font control so we "fake" it by placing a StringEdit field followed by a Button control together in one form group. We need to set few of the group's properties to make sure it has two columns, and there is no space between group elements, so the user will see those two controls as one.

The last thing to do is to modify the button. To make sure that it looks exactly like existing Dynamics AX font controls, we change its properties so that the appearance changes to a small three dot button. The clicked() method has to be overridden with the code that calls the lookup. Here, we use chooseFont() method of WinAPI application class to display the standard Windows font selection dialog. This method accepts four arguments:

  1. 1. Current window handler.

  2. 2. Selection between screen or printer font.

  3. 3. Current font name, which will be preselected in the lookup.

  4. 4. Current font size, which will be preselected in the lookup.

The chooseFont() method returns a container of two elements, where the first one is font name and the second one is a size. Note that although the font selection dialog contains Font style section, the style is not returned by this method.

Other  
  •  Microsoft Dynamics AX 2009 : Building Lookups - Picking a color
  •  Microsoft Dynamics AX 2009 : Building Lookups - Selecting a file
  •  Programming .NET Components : Remoting - Leasing and Sponsorship (part 3) - Sponsorship Management
  •  Programming .NET Components : Remoting - Leasing and Sponsorship (part 2) - Providing a Sponsor, Leasing and Remote Activation Modes
  •  Programming .NET Components : Remoting - Leasing and Sponsorship (part 1) - Lease Properties, Configuring a Lease, Renewing a Lease
  •  DisplayPort 1.2 - Meet HDMI’s Smarter Brother
  •  HP ProLiant Servers AIS : Processors and Multiprocessing - The Processor Performance Evolution
  •  HP ProLiant Servers AIS : Processors and Multiprocessing - How Processors Work
  •  How To Get The Best From Your Batteries (Part 2)
  •  How To Get The Best From Your Batteries (Part 1)
  •  
    Top 10
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
    - Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
    - Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
    Video Sports
    - The Banner Saga 2 [PS4/XOne/PC] PC Launch Trailer
    - Welkin Road [PC] Early Access Trailer
    - 7th Dragon III Code: VFD [3DS] Character Creation Trailer
    - Human: Fall Flat [PS4/XOne/PC] Coming Soon Trailer
    - Battlefleet Gothic: Armada [PC] Eldar Trailer
    - Neon Chrome [PS4/XOne/PC] PC Release Date Trailer
    - Rocketbirds 2: Evolution [Vita/PS4] Launch Trailer
    - Battleborn [PS4/XOne/PC] 12 Min Gameplay Trailer
    - 7 Days to Die [PS4/XOne/PC] Console Trailer
    - Total War: Warhammer [PC] The Empire vs Chaos Warriors Gameplay Trailer
    - Umbrella Corps [PS4/PC] Mercenary Customization Trailer
    - Niten [PC] Debut Trailer
    - Stellaris [PC] Aiming for the Stars - Dev. Diary Trailer #1
    - LawBreakers [PC] Dev Diary #4: Concept Art Evolutions
    programming4us programming4us
    programming4us
     
     
    programming4us