Skip to main content
.NET Framework 4.5.2+

How to: Adjust Window Size and Style (WinForms)

  • 3 minutes to read

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_Win

Tip

A similar example for ASP.NET Web Forms is available in the How to: Adjust the Size and Style of Pop-up Dialogs (ASP.NET Web Forms) topic.

Set the Default Size and Style of Pop-up Windows

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.

Customize a Pop-up Window Depending on its View

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.

  • Minimum form size may be set by default (the InitialMinimumSize property).
  • Size may be calculated dynamically based on the content.
  • The Form may have resizing restrictions (the IsSizeable property).
  • The Form size may automatically shrink (the AutoShrink property)
  • The Form may expand to occupy the whole space (the Maximized property).
See Also