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.
Programmatically assign XAF application window size and position at startup
Answers approved by DevExpress Support
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.
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;
}
}