开发者

control desktop maximize area in C#

Is there a way开发者_运维问答 to control what space of the screen windows can be maximized to, in C#


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
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜