C# Form Sizing


A form, sizing itself to the borders of the screen working area.I subscribed this article because I had a little problem when I wanted to make my form take the whole free screen working area.

I mean not the whole screen, but only the fre working area.For example if the TaskBar(Start menu) is visible, the working area will be a little bit smaller the the whole screen area.

So if we want our form not to cover the Start menu in windows -> we could use this code :

//Make a form take the whole Screen Working Area
// project created on 01.10.2001 ?. at 06:28
// Author : Pavel Tsekov
using System;
using System.Windows.Forms;
using System.Drawing;

class MainForm : Form
{
public MainForm()
{
//create an object of class Rectangle (rect)
Rectangle rect=new Rectangle();
//rect get data from the function returning the working area of the screen
rect=Screen.GetWorkingArea(this);
//place our form at left
this.Left=0;
//place our form at top
this.Top=0;
//set the size (width and height) of our form as the size of the screen
//working area
this.Size=new Size(rect.Width,rect.Height);
//set the caption(text) of the form. The size of the working area is displayed
//and then the size of the whole screen
this.Text="SCR Working area:" + Screen.GetWorkingArea(this).ToString()+" || SCR Real area: " + Screen.GetBounds(this).ToString();
}

public static void Main(string[] args)
{
Application.Run(new MainForm());
}
}

Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!