Center Screen on Load via c# Customization

I created a screen customization for an updatable dashboard for use on the handheld menu. I’m having a problem where it loads outside the visible area of the handheld screen.

Is there a way to center the screen on the load event?

There almost certainly is.

But usually the easiest way to fix this problem is to find where on your development computer is equivalent to where you want the screen to open on the handheld, open that screen in developer mode and move it there, then save layouts. Then it will always open there by default for everybody.

1 Like

on MainController_Load event

MainController.StartPosition = FormStartPosition.CenterScreen;

@prakash Thanks. Couldn’t get that to work. The code compiles, but it doesn’t appear to have any effect. I also tried the method below to explicitly set the location, but it didn’t seem to have any effect either. I’m wondering if This has to happen prior to the load event?

int x = Screen.PrimaryScreen.Bounds.Width - MainController.PreferredSize.Width;
int y = Screen.PrimaryScreen.Bounds.Height - MainController.PreferredSize.Height;
MainController.Location = new Point(x/2, y/2 );

can you try below code in maincontroller_load event?

this.MainController.StartPosition = FormStartPosition.CenterScreen;
MainController.Location = new System.Drawing.Point((Screen.PrimaryScreen.Bounds.Size.Width / 2) - (MainController.Size.Width / 2), (Screen.PrimaryScreen.Bounds.Size.Height / 2) - (MainController.Size.Height / 2));

Same thing. It looks like something is setting the location after the load event.

I was able to reposition the screen on a field change event successfully. This requires user interaction before the screen centers though. If I can figure out the event that immediately proceeds the Load event, I could get this working the way I want.

In developer mode but not in customization mode, go to Actions and click Reset Layouts to Base. Then go into customization mode and save it. (Note; it might be that you also need to click “Save Layouts” when doing this)
Note that like @dhewi said, the position on your screen where this is developed and saved is where it places the size/start location of the form.

If you want code, it would look like this:

//Center the form to screen
private void UD01Form_Load(object sender, EventArgs args)
{
  UD01Form.StartPosition = FormStartPosition.CenterScreen;
}

//Make the form fixed size and center screen
private void UD01Form_Load(object sender, EventArgs args)
{
  UD01Form.StartPosition = FormStartPosition.CenterScreen;
  UD01Form.MaximizeBox = false;
  UD01Form.MinimizeBox = false;
  UD01Form.FormBorderStyle = FormBorderStyle.FixedDialog;
}

@Aaron_Moreng Same problem. It is honoring the CenterScreen setting, but after the Load event is complete it repositions itself. I threw in a MessageBox after the Fixed Dialog line and the Screen is centered until I hit OK on the message.

Does the Hand Held have any sort of virtual screen sizing, where the “center” is actually off screen like you’re seeing?

What if you try to set the window to the Upper Left corner?

Possible, I’m testing from a standard desktop though (Expecting if it to center to any screen its opened on). Not centering to anything.

Just the dashboard’s window, right?

window is centered on your desktop?

The initial Handheld

Correct, The HH main menu loads in the correct location. Just my dashboard loads off-center.

Just spit balling here … But I wonder what the correlation (if any) is between the location of that dashboard’s window in regular (desktop) mode, and the position of the dashboard relative to the main HH window

Does moving the dashboard (and jumping through the hoops of using “save layouts”) while in desktop mode, change where it appears in HH mode?

and one last thing … Is it possible a personalization being applied to the dashboard when in handheld mode?

Like I said, just throwing things out there. Very strange that it repositions itself after you dismiss that MessageBox.

I think this all revolves around this being a dashboard assembly. The only way I found to change the load location of the screen is by changing where the dashboard is located when initially deployed. Deploying while located in the top left corner loads the menu item in the center of the handheld.