顺便提一下的是,Winforms支持重新确立控制。 您可以将其移至显示完全筛选的临时形式。 所有正常活动处理人员仍然照常工作。 这里的样本实施是为了控制:
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();
}
样本使用:
private void button1_Click(object sender, EventArgs e) {
ShowFullScreen(tabControl1);
}