Sizing a Control Add-in on a Page
By default, the size of a control add-in on a page is determined by the System.Drawing.Size class of the control. The size is static, so when the page is resized in the Microsoft Dynamics NAV Windows client, the control add-in size will remain the same.
Changing the Size of a Control Add-in
To change the size of the control add-in and set it to resize with the page window size, you implement the WinFormsControlAddInBase.ApplySize method. This method has the following syntax.
public void ApplySize(DisplaySize width, DisplaySize height);
Each dimension is defined by the DisplaySize method. This method has the following syntax.
DisplaySize.DisplaySize(int minimum, int preferred, int maximum)
The DisplaySize parameters specify the control add-in size as follows.
||An integer that sets the minimum width or height, in pixels, of the control add-in. The control add-in will not resize smaller than this value regardless of the size of the page window.|
||An integer that sets the initial width or height, in pixels, of the control add-in when the page first opens.|
||An integer that sets the minimum width or height, in pixels, of the control add-in. The control add-in will not resize larger than this value regardless of the size of the page window.|
The following code example shows the control add-in width (in pixels) set to: minimum 100, preferred 600, and maximum 1000. The height (in pixels) is set to: minmum 10, preferred 20, and maximum 200.
this.ApplySize(new DisplaySize(101, 600, 1000), new DisplaySize(10, 20, 200));
Sizing a Control Add-in According to the Size of Other Page Controls
There might be instances when you want the control add-in to use the same size of other controls on the page. By using page controls, Dynamics NAV automatically determines the size based on the control’s data type. To set this behavior on the control add-in, for each dimension, use either
null. You can set one dimension to default and the other to custom values.
The following code example shows the control add-in width in pixels set to default and the minimum height to 10, a preferred height set to 20, and the maximum height set to 200.
this.ApplySize(DisplaySize.Default, new DisplaySize(10, 20, 200));
In this case, the control add-in width resembles other field controls that have the same C/AL data type on the page.