Monday, December 29, 2008

How to resize Workarea of desktop in C#

public struct Rect
{
public Int32 Left, Top, Right, Bottom;
}

The code below is that the workarea is reduced by the height of Form and the Form is placed bottom of the workarea. It is like application of Cash Fiesta6

private void button1_Click(object sender, EventArgs e)
{
Rect DeskArea = new Rect();
SystemParametersInfo(48/*SPI_GETWORKAREA*/, 0, ref DeskArea, 2/*SPIF_SENDCHANGE*/);
this.Left = 0;
this.Width = DeskArea.Right;
this.Top = DeskArea.Bottom - this.Height - 4;
DeskArea.Bottom = DeskArea.Bottom - 150;
SystemParametersInfo(47/*SPI_SETWORKAREA*/, 0, ref DeskArea, 2/*SPIF_SENDCHANGE*/);
}

And now you need to replace the orkarea to its original size.

private void button2_Click(object sender, EventArgs e)
{
Rect DeskArea = new Rect();
SystemParametersInfo(48/*SPI_GETWORKAREA*/, 0, ref DeskArea, 2/*SPIF_SENDCHANGE*/);
DeskArea.Bottom = DeskArea.Bottom + 150;
SystemParametersInfo(47/*SPI_SETWORKAREA*/, 0, ref DeskArea, 2/*SPIF_SENDCHANGE*/);
}

0 comments: