开发者

C# Winform: Full Screen UserControl

开发者 https://www.devze.com 2022-12-29 13:59 出处:网络
I have an application with main form. the main form has menu and some toolstrip and one user control set the dock to Fill. how can i provide full screen view so that user control set to full screen an

I have an application with main form. the main form has menu and some toolstrip and one user control set the dock to Fill. how can i provide full screen view so that user control set to full screen and all men开发者_开发问答u and toolstrip hide from main form.


Not that I've ever done it - by my approach would be to:

In your full screen 'mode' do this:

switch off the form border set controlbox to false (gets rid of the titlebar and top-left window menu) make the menu/toolstrip invisible.

This is done with the 'Visible' property of those controls.

Now, you should be able to set the window state of the form to Maximized.

EDIT - Code Sample:

Paste this into the code file of a new forms app

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;
    }
  }
}


In addition to that, before maximizing, do this:

this.TopMost = true;

...to put your control over the windows bottom panel and start button (basically this will fill the entire screen).


I would programmatically change UI, hiding all container panels except the work-area container panel, where user control is located.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号