DevExpress PopUp Window Size State

Date: 2024-05-14

https://supportcenter.devexpress.com/ticket/details/t755411/programmatically-assign-xaf-application-window-size-and-position-at-startup

using View = DevExpress.ExpressApp.View;
/// <summary>
/// Controller om sommige gewone popup detailviews te resizen. De lookup listviews vallen hier niet onder
/// Ook zorgt deze controller voor een soort CenterScreen van de beïnvloede popups. CenterParent werkt helaas
/// niet want er is geen parent form bekend.
/// </summary>
[DesignerCategory(OneSysConstants.NoDesigner)]
public class SetPopupSizeVC : WindowController
{
    protected override void OnActivated()
    {
        base.OnActivated();
        Window.TemplateChanged += Window_TemplateChanged;
    }

    protected override void OnDeactivated()
    {
        Window.TemplateChanged -= Window_TemplateChanged;
        base.OnDeactivated();
    }

    private void Window_TemplateChanged(object sender, EventArgs e)
    {
        if (Window.Template is Form && Window.Template is ISupportStoreSettings)
        {
            ((ISupportStoreSettings)Window.Template).SettingsReloaded += OnFormReadyForCustomizations;
        }
    }

    private void OnFormReadyForCustomizations(object sender, EventArgs e)
    {
        if (!IsFormSizeProvider(Window.View)) return;
        ((Form)sender).Size = ((IFormSizeProvider)Window.View.CurrentObject).GetFormSize();
        ((Form)sender).StartPosition = FormStartPosition.CenterParent;
    }

    private bool IsFormSizeProvider(View view) => view?.CurrentObject is IFormSizeProvider;
}
public partial class MainWindowController : WindowController  
{  
    public MainWindowController()  
    {  
        InitializeComponent();  
        // Target required Windows (via the TargetXXX properties) and create their Actions.  
        TargetWindowType = WindowType.Main;  
    }  

    protected override void OnActivated()  
    {  
        base.OnActivated();  
        // Perform various tasks depending on the target Window.  
        Window.TemplateChanged += WindowsTemplateChanged;  
    }  
    private void WindowsTemplateChanged(object sender, EventArgs e)  
    {  
        if (Window.Template is System.Windows.Forms.Form && Window.Template is ISupportStoreSettings)  
        {  
            ((ISupportStoreSettings)Window.Template).SettingsReloaded += OnFormReadyForCustomizations;  
        }  
    }  

    protected override void OnDeactivated()  
    {  
        Window.TemplateChanged -= WindowsTemplateChanged;  
        // Unsubscribe from previously subscribed events and release other references and resources.  
        base.OnDeactivated();  
    }  

    private void OnFormReadyForCustomizations(object sender, EventArgs e)  
    {  
        int newWidth = 1280;  
        int newHeight = 720;  

        Form mainForm = sender as System.Windows.Forms.Form;  
        // Ensure that the window state is normal, not maximized  
        mainForm.WindowState = FormWindowState.Normal;  
        // Setup window location to center of Window screen  
        mainForm.SetDesktopLocation(  
            (int)((SystemInformation.VirtualScreen.Width - newWidth) /2),  
            (int)((SystemInformation.VirtualScreen.Height - newHeight)/2));  
        mainForm.Width = newWidth;  
        mainForm.Height = newHeight;  

    }  
}  
85320cookie-checkDevExpress PopUp Window Size State