c#全屏
1.新建一个窗口,设置 FormBorderStyle为None,WindowState为Maximized,TopMost为True。然后具体代码如下:
AddEventKeyUp(control); 原来的parent.Controls.Clear(); frmFullscreen frm = new frmFullscreen(); frm.Controls.Add(control); frm.ShowDialog();
void control_KeyUp(object sender, KeyEventArgs e) {
if (e.KeyCode == Keys.Escape) {
if (control != null) {
if (frm != null) {
frm.Controls.Clear();
原来的parent.Controls.Add(control);// 这里不能和下面的Close顺序错了,要不然会引起错误,因为Close后把控件销毁了。
frm.Close();
frm = null;
}
}
}
}
例子:
private void 全屏ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.frm = new FormFillScreen();
panel2.Controls.Clear();
frm.Focus();
frm.Controls.Add(axMapControl1);
frm.ShowDialog();
}
private void axMapControl1_OnKeyUp(object sender, IMapControlEvents2_OnKeyUpEvent e)
{
if (e.keyCode == 27)
{
if (axMapControl1 != null)
{
if (this != null)
{
frm.Controls.Clear();
panel2.Controls.Add(axMapControl1);
frm.Close();
frm = null;
}
}
}
}
2.
要设置keypreview为true
3.
- //单击进入全屏
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- this.Topmost = true;
- this.WindowStyle = System.Windows.WindowStyle.None;
- this.WindowState = System.Windows.WindowState.Maximized;
- }
- //按Esc键退出全屏
- private void Grid_PreviewKeyDown(object sender, KeyEventArgs e)
- {
- if (e.Key == Key.Escape)//Esc键
- {
- this.WindowState = System.Windows.WindowState.Normal;
- this.WindowStyle = System.Windows.WindowStyle.SingleBorderWindow;
- }
- }

浙公网安备 33010602011771号