0

Im working on a windows form program and I want to make the main form always maximized ,I've tried setting the WindowState to Maximized and FormBorderStyle to FixedDialog/FixedSingle and it works but the maximize button is still there so I tried setting the MaximizeBox to false but then the form is full screen and it totally covers the taskbar which is the problem ,I don't want it to be over the taskbar. If anyone knows a solution or ever an alternative solution to the problem please feel free to help me out.

  • 1
    Possible duplicate of [How do I make a WinForms app go Full Screen](https://stackoverflow.com/questions/505167/how-do-i-make-a-winforms-app-go-full-screen) – jeroenh Aug 18 '18 at 18:27

1 Answers1

4

Keep FormBorderStyle = Sizable. Set MaximizeBox = false and MinimizeBox = false. As code behind use

public partial class frmFixedMaximized : Form
{
    private bool _changing;

    public frmFixedMaximized()
    {
        InitializeComponent();
        WindowState = FormWindowState.Maximized;
    }

    private void frmFixedMaximized_Shown(object sender, EventArgs e)
    {
        // Make resizing impossible.
        MinimumSize = Size;
        MaximumSize = Size;
    }

    private void frmFixedMaximized_LocationChanged(object sender, EventArgs e)
    {
        if (!_changing) {
            _changing = true;
            try {
                // Restore maximized state.
                WindowState = FormWindowState.Minimized;
                WindowState = FormWindowState.Maximized;
            } finally {
                _changing = false;
            }
        }
    }
}

The reason for this code is that a user can still drag a window by holding its title bar. The _changing variable prevents the LocationChanged event handler to trigger itself in an endless loop.

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
  • thank you so much ,I had that problem of holding the title bar but i didnt want to mention it because i didnt know how to describe it and i didnt want to make people confused – Ahmad Alshaib Aug 19 '18 at 10:23