问题
I would center a form in an ActiveWorkbook, how to get the screen/window position of the workbook?
回答1:
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);
}
回答2:
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();
来源:https://stackoverflow.com/questions/1618256/how-to-get-the-screen-position-of-an-active-workbook