Usable ClientRectangle for Form

  • Thread starter Thread starter Bit Twiddler
  • Start date Start date
B

Bit Twiddler

Hi,

I am performing drawing directly on the surface of a WinForm (double
buffering).

My form has a menu, statusbar, etc.

The ClientRectangle of my form includes the areas taken up by the menu,
statusbar, etc. What I want to get is a rectangle that represents the area
of the form where I need to do my drawing. Is there an easy way to get his
rectangle or do I have to calculate it myself all the time?

Thanks,
BT
 
I don't know if this is the proper solution, but I ended up using a
transform on the graphics object to translate the drawing so that that is
automatically occurs UNDER the status bar:

private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;

// Start drawing BELOW the statusbar
Matrix matrix = new Matrix();
matrix.Translate(0, menuStrip1.Height);
g.Transform = matrix;

// Now (0,0) is below the statusbar
g.DrawRectangle(Pens.Red, 0, 0, ...);
...
 
Form.ClientRectangle is what you are after.
personally I would do

Rectangle client = ClientRectangle;
e.Graphics.SetClip(client);
e.Graphics.TranslateTransform(client.X, client.Y);
 
Back
Top