移动表格到指定的屏幕 [英] Move Form onto specified Screen

查看:174
本文介绍了移动表格到指定的屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何移动指定System.Windows.Forms.Form中到另一个比主画面。我有组合框可用的屏幕,其中用户选择哪个屏幕,他喜欢和我的应用程序应该将其窗口之一到该屏幕列表。

I am trying to figure out how to move specified System.Windows.Forms.Form onto another than primary screen. I have ComboBox with list of available screens where user selects whichever screen he likes and my application is supposed to move one of its windows onto that screen.

我只有一个屏幕上我的笔记本电脑,没有外接显示器,所以组合框在我的电脑上只提供了一种选择。我觉得minimalising所需窗口,动它的左上角在选定屏幕上的边界和maximilising中心将做的工作,对不对?我不能测试它。这是一个很好的路要走?

I have only one screen on my laptop and no external monitor, so ComboBox on my computer offers only one option. I think minimalising desired window, moving it's left corner in the center of selected screen's Bounds and maximilising would do the job, right? I just can't test it. Is this a good way to go?

在此先感谢!

推荐答案

下面是我做什么,作为一个简单的测试...

Here's what I did, as a simple test...

我添加了一个简单的包装类,这样我可以改变的的ToString调用发生了什么(我只是想看看在组合框中列出的名称)

I added a simple wrapper class so that I could change what happens on the ToString call (I only wanted to see the name listed in the combo box)

private class ScreenObj
{
    public Screen screen = null;

    public ScreenObj(Screen scr)
    {
        screen = scr;
    }

    public override string ToString()
    {
        return screen.DeviceName;
    }
}

在窗体加载事件我说这样的:

In the form load event I added this:

foreach(Screen screen in Screen.AllScreens)
{
     cboScreens.Items.Add(new ScreenObj(screen));
}

和组合框我有这样的选择的指数变化情况:

And for the selected index change event of the combo box I had this:

private void cboScreens_SelectedIndexChanged(object sender, EventArgs e)
{
    object o = cboScreens.SelectedItem;
    if(null == o)
        return;

    ScreenObj scrObj = o as ScreenObj;
    if(null == scrObj)
        return;

    Point p = new Point();

    p.X = scrObj.screen.WorkingArea.Left;
    p.Y = scrObj.screen.WorkingArea.Top;

    this.Location = p;
}

据移动的形式,我的每一个画面的左上角。

It moved the form to the upper left hand corner of each of my screens.

这篇关于移动表格到指定的屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆