Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

control desktop maximize area in C#

Is there a way to control what space of the screen windows can be maximized to, in C#

like image 238
Lee Louviere Avatar asked Jan 29 '26 10:01

Lee Louviere


1 Answers

To limit the size of your application's window, use the Form.MaximizedBounds property. You can use the Screen class to get the bounds of your current (or some other) screen.

For example, this will maximize your form to left half of the primary screen:

public partial class MyForm : Form
{
    public MyForm()
    {
        InitializeComponent();

        // set width to 1/2 of screen
        Rectangle screenBounds = Screen.PrimaryScreen.Bounds;
        screenBounds.Width = screenBounds.Width / 2;            
        this.MaximizedBounds = screenBounds;

        // maximize
        this.WindowState = FormWindowState.Maximized;
    }
}

[Edit]

If you want to dock your window to one side of the screen and limit the remaining desktop area for other applications, you might be interested in registering a custom APPBAR through Windows API.

Check the following links:

  • Microsoft: Creating an Application Desktop Toolbar
  • CodeProject: AppBar using C#
  • CodeProject: C# does Shell, Part 3
like image 111
Groo Avatar answered Feb 01 '26 00:02

Groo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!