tags:

views:

46

answers:

2

I would center a form in an ActiveWorkbook, how to get the screen/window position of the workbook?

A: 

Didn't find a good solution but found an acceptable one:

int top = Application.Top + Application.PageSetup.TopMargin + Application.PageSetup.HeaderMargin + Application.Commandbars["Ribbon"].Height; int left = Application.Left + Application.PageSetup.LeftMargin;

Form popup = new Form{ Top = top, Left = left, StartPosition = FormStartPosition.Manual, Width=400, Height=300}; popup.Show();

PerlDev
+1  A: 

C# example..

private void setFormPos(Form frm)
{
   int top = Application.Top + Application.PageSetup.TopMargin + Application.PageSetup.HeaderMargin + Application.Commandbars["Ribbon"].Height;
   int left = Application.Left + Application.PageSetup.LeftMargin;
   frm.Left = (left / 2);
   frm.Top = (top / 2);
}
Anonymous Type