Output to another Window

和自甴很熟 提交于 2019-12-02 18:13:32

问题


Is there a way to direct a form in VB.NET to open and maximize in the second monitor. That is if there are two monitors displayed, to have the form load in the second window maximized by default?

Say a program was made with two forms and a computer has two monitors attached.

I want FormA to show in MonitorA by default and FormB to show in MonitorB maximized by default.

EDIT: Further edited for clarity.


回答1:


The first thing is to get information about available screens. You can get that from Screen.AllScreens. Next is to determine how many screens there are (note that there may be more than two). Then you need to decide how to identify the "second" screen (for instance, the first one that where the Primary property is false.

When that is done, I guess that the simplest way is to move the form to a location that is within the Bounds of the desired screen, and then maximize it.

Here is a sample method that opens a form maximized on a specified screen:

public static void ShowMaximizedOnScreen(Screen screen, Form form)
{
    form.Location = screen.Bounds.Location;
    form.WindowState = FormWindowState.Maximized;
    form.StartPosition = FormStartPosition.Manual;
    form.Show();
}


来源:https://stackoverflow.com/questions/9413250/output-to-another-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!