简体   繁体   中英

Resize the screens WorkingArea during runtime

using following code I determine where and how I want to position my side panel:

var sc = Screen.FromHandle(this.Handle);
var w = sc.WorkingArea.Width / 6;
var h = sc.WorkingArea.Height;
var x = sc.WorkingArea.Right - w;
var y = sc.WorkingArea.Top;

this.Size = new Size(w, h);
this.Location = new Point(x, y);

The side panel is just another Form. This works perfectly fine and exactly how I want it to. However I've had some programs, that resized the screens WorkingArea so that other applications only took a restricted area of the screen when being maximized.

I couldn't find any information online considering this topic, I suppose because I lack the correct term for my goal.

Any Input is appreciated!

I'm guessing that you want the application to resize specifically to a certain size and go to a certain position rather than it going fullscreen.

As far as I know, this is only possible if you use a custom button as the resize control instead of the standard controls present when using the "Sizable" layout option.

You could create a button and write the following into the buttons click void:

private void button_Click(object sender, EventArgs e)
{

    this.Location = new Point(/*XPosition*/, /*YPosition*/);
    this.Size = new Size(/*HEIGHT*/, /*WIDTH*/);
    
}

This will make the form change its position and size to the size and position you want.

I hope I understood you correctly and hope this helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM