如何创建一组控件的全屏视图,属于一个Tab页 [英] How create a fullscreen view of a group of controls, that belongs to a tabpage

查看:131
本文介绍了如何创建一组控件的全屏视图,属于一个Tab页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道什么是创建一个TabPage的控制全屏视图的正确方法。当前页有其他控制,并且控制具有订阅各种事件。我试图创建一个新的全屏的形式和复制选项卡这种形式的所有控件,但这种方法,我需要重新订阅每个控制到相应的处理程序。如果我只添加订阅仍然引用但当全屏形式接近也引用复制的控件都将丢失。

i would like to know what is the correct way to create a fullscreen view of a tabpage control. This page has other controls, and that controls has various events that are subscribed. I was trying creating a new fullscreen form and copy all controls of the tabs to that form, but with this approach i need to resubscribe every control to the corresponding handler. If i only add the references the subscription remains but when the fullscreen form is close also the referenced copied controls are lost.

推荐答案

这可以通过的WinForms'的重排根控制支持下优雅完成。你可以将它移动到的全屏显示一个临时表。所有正常的事件处理程序仍照常上班。下面是一个示例实现,它可以用于任何控制:

This can be elegantly done by Winforms' support for reparenting a control. You could move it to a temporary form that's displayed full-screen. All the normal event handlers still work as usual. Here's a sample implementation, it works for any control:

    public static void ShowFullScreen(Control ctl) {
        // Setup host form to be full screen
        var host = new Form();
        host.FormBorderStyle = FormBorderStyle.None;
        host.WindowState = FormWindowState.Maximized;
        host.ShowInTaskbar = false;
        // Save properties of control
        var loc = ctl.Location;
        var dock = ctl.Dock;
        var parent = ctl.Parent;
        var form = parent;
        while (!(form is Form)) form = form.Parent;
        // Move control to host
        ctl.Parent = host;
        ctl.Location = Point.Empty;
        ctl.Dock = DockStyle.Fill;
        // Setup event handler to restore control back to form
        host.FormClosing += delegate {
            ctl.Parent = parent;
            ctl.Dock = dock;
            ctl.Location = loc;
            form.Show();
        };
        // Exit full screen with escape key
        host.KeyPreview = true;
        host.KeyDown += (KeyEventHandler)((s, e) => {
            if (e.KeyCode == Keys.Escape) host.Close();
        });
        // And go full screen
        host.Show();
        form.Hide();
    }



使用范例:

Sample usage:

    private void button1_Click(object sender, EventArgs e) {
        ShowFullScreen(tabControl1);
    }

这篇关于如何创建一组控件的全屏视图,属于一个Tab页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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