簡體   English   中英

C#Winform:全屏用戶控件

[英]C# Winform: Full Screen UserControl

我有一個主表單的應用程序。 主窗體有菜單和一些工具條,一個用戶控件將dock設置為Fill。 如何提供全屏視圖,以便用戶控件設置為全屏,並且所有菜單和工具條都隱藏在主窗體中。

不是說我曾經做過 - 我的方法是:

在您的全屏“模式”中執行此操作:

關閉窗體邊框設置控件框為false(刪除標題欄和左上角窗口菜單)使菜單/工具條不可見。

這是通過這些控件的“可見”屬性完成的。

現在,您應該能夠將窗體的窗口狀態設置為“最大化”。

編輯 - 代碼示例:

將其粘貼到新表單應用程序的代碼文件中

public partial class Form1 : Form
{
  public Form1()
  {
    InitializeComponent();
  }
  private void Form1_Load(object sender, EventArgs e)
  {
    this.ControlBox = false;
    this.FormBorderStyle = FormBorderStyle.None;
    this.WindowState = FormWindowState.Maximized;
  }

  private void Form1_KeyDown(object sender, KeyEventArgs e)
  {
    //example of how to programmatically reverse the full-screen.
    //(You will have to add the event handler for KeyDown for this to work)
    //if you are using a Key event handler, then you should set the 
    //form's KeyPreview property to true so that it works when focus
    //is on a child control.
    if (e.KeyCode == Keys.Escape)
    {
      this.ControlBox = true;
      this.FormBorderStyle = FormBorderStyle.Sizable;
      this.WindowState = FormWindowState.Normal;
    }
  }
}

除此之外, 最大化之前 ,請執行以下操作:

this.TopMost = true;

...控制窗口底部面板和開始按鈕(基本上這將填滿整個屏幕)。

我會以編程方式更改UI,隱藏除工作區容器面板之外的所有容器面板,用戶控件所在的位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM