How to get the screen position of an active workbo

2019-08-28 10:16发布

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

标签: vsto position
2条回答
祖国的老花朵
2楼-- · 2019-08-28 10:32

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();
查看更多
走好不送
3楼-- · 2019-08-28 10:46

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);
}
查看更多
登录 后发表回答