zoukankan      html  css  js  c++  java
  • 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.

    1. //单击进入全屏  
    2. private void Button_Click(object sender, RoutedEventArgs e)  
    3. {  
    4.     this.Topmost = true;  
    5.     this.WindowStyle = System.Windows.WindowStyle.None;  
    6.     this.WindowState = System.Windows.WindowState.Maximized;  
    7. }  
    8. //按Esc键退出全屏  
    9. private void Grid_PreviewKeyDown(object sender, KeyEventArgs e)  
    10. {  
    11.     if (e.Key == Key.Escape)//Esc键  
    12.     {  
    13.         this.WindowState = System.Windows.WindowState.Normal;  
    14.         this.WindowStyle = System.Windows.WindowStyle.SingleBorderWindow;  
    15.     }  
    16. }  
  • 相关阅读:
    Wooden Sticks(hdu1051)
    Leftmost Digit(hdu1060)(数学题)
    Sum of Remainders(数学题)
    Brain Network (medium)(DFS)
    Brain Network (easy)(并查集水题)
    Collective Mindsets (medium) (逻辑题)
    Collective Mindsets (easy)(逻辑题)
    RMQ with Shifts(线段树)
    Throwing Dice(概率dp)
    圆桌会议
  • 原文地址:https://www.cnblogs.com/janeaiai/p/4941749.html
Copyright © 2011-2022 走看看