Ticket T755411
Visible to All Users

Programmatically assign XAF application window size and position at startup

created 6 years ago

When I run XAF application and close, XAF save the location and main window size and restore next time I open the application. Can I programmatically assign the window position and size to be the same at startup? For example, always start XAF at center screen, XAF main window size 1280x720  every time I open the application.

Answers approved by DevExpress Support

created 6 years ago (modified 6 years ago)

Hello Aod,

To override end-user form settings, handle the Window's ISupportStoreSettings.SettingsReloaded event. Please refer to the How to: Adjust the Windows' Size and Style topic for additional information.

    Comments (2)

      I follow your answer and the following code works for me, now every time XAF application runs it's always on the same location and same size. I need this to create tutorial video of the application without having to resize my desktop and capture video.

      Your recommended solution is perfect! thank you.

      C#
      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; } }
      Anatol (DevExpress) 6 years ago

        You are welcome!

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.