expressappframework-117231-ui-construction-templates-in-winforms-how-to-adjust-the-windows-size-and-style.md
In WinForms XAF applications, end-users can drag the size grip in the bottom-right corner to resize windows. You can also customize the initial form size in code. This topic describes how to programmatically resize and customize windows depending on the displayed View. Pop-up dialog windows are used as an example.
Popup windows can be customized in the XafApplication.CustomizeTemplate and Frame.TemplateChanged events. Create a new Window Controller and subscribe to either of these events when the Controller is activated (Controller.Activated event) as shown below.
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Templates;
//...
public class CustomizeFormSizeController : WindowController {
protected override void OnActivated() {
base.OnActivated();
Window.TemplateChanged += Window_TemplateChanged;
}
private void Window_TemplateChanged(object sender, EventArgs e) {
if(Window.Template is System.Windows.Forms.Form &&
Window.Template is ISupportStoreSettings) {
((ISupportStoreSettings)Window.Template).SettingsReloaded +=
OnFormReadyForCustomizations;
}
}
private void OnFormReadyForCustomizations(object sender, EventArgs e) {
if(YourCustomBusinessCondition(Window.View)) {
((System.Windows.Forms.Form)sender).Size =
((IFormSizeProvider)Window.View.CurrentObject).GetFormSize();
}
}
private bool YourCustomBusinessCondition(View view) {
return view != null && view.CurrentObject is IFormSizeProvider;
}
protected override void OnDeactivated() {
Window.TemplateChanged -= Window_TemplateChanged;
base.OnDeactivated();
}
}
In this code, the target window template is accessed by subscribing to the TemplateChanged event from a Controller. Then, handle the ISupportStoreSettings.SettingsReloaded event to make customizations after the default XAF template settings were applied. Also, you can handle the Form.HandleCreated or Form.Load event. Place your customization code into the OnFormReadyForCustomizations event handler.
As a result, the size of the target pop-up window is determined depending on the parent window size.
If you want to customize pop-up windows for a particular type, create a ObjectViewController<ViewType, ObjectType> Controller and specify the business object type. To maximize the DemoObject pop-up window, do the following:
See the example in the PopupWindowShowAction class description.
Note
Certain form templates (e.g., LookupForm , PopupForm , LookupControlTemplate ) may have particular specifics.
See Also
How to: Adjust the Size and Style of Pop-up Dialogs (Blazor)