tags:

views:

20

answers:

1

I have a WinForms application.

Application has menustrip, toolstrip and several panels.

I want to stretch one of that panels on fullscreen. I want that panel covers all screen include taskbar.

How do I do it ?

============================================

I used an answer of Hans Passant:

public partial class Form1 : Form
{
    Size _panel1Size;

    public Form1()
    {
        InitializeComponent();

        _panel1Size = panel1.Size;
    }

    void bFullScreen_Click(object sender, EventArgs e)
    {
        this.FormBorderStyle = FormBorderStyle.None;
        this.WindowState = FormWindowState.Maximized;
        this.panel1.Size = this.ClientSize;
    }

    void bGoBack_Click(object sender, EventArgs e)
    {
        this.FormBorderStyle = FormBorderStyle.FixedDialog;
        this.WindowState = FormWindowState.Normal;

        panel1.Size = _panel1Size;
    }
}
+1  A: 

Getting a form to cover the taskbar requires it to be borderless. You'll need to detect the window state change in the OnResize event. Something like this:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        panel1Size = panel1.Size;
        prevState = this.WindowState;
    }
    private Size panel1Size;
    private FormWindowState prevState;

    protected override void OnResize(EventArgs e) {
        if (prevState != this.WindowState) {
            prevState = this.WindowState;
            if (this.WindowState == FormWindowState.Maximized) {
                this.FormBorderStyle = FormBorderStyle.None;
                panel1.Size = this.ClientSize;
            }
            else if (this.WindowState == FormWindowState.Normal) {
                this.FormBorderStyle = FormBorderStyle.Sizable;
                panel1.Size = panel1Size;
            }
        }
        base.OnResize(e);
    }

    private void button1_Click(object sender, EventArgs e) {
        this.WindowState = FormWindowState.Normal;
    }
}

There's a flaw, it won't restore to the exact same size. No easy fix for that.

Hans Passant
On second thought, easy fix is to restore the ClientSize.
Hans Passant
@Hans, i did it. I added my solution to my question (first post). What do you mean by flaw ? I didn't see any distortion.
nik