1

I've got a System.Windows.Forms.Form where I need to set the size of the client area at runtime. Strangely, though, even when I set the ClientSize property to 800x600, the area is smaller by 4 pixels on the right and bottom sides, which causes my content to be clipped by 4 pixels in both directions.

This behavior is observed with both the Windows XP and Windows Classic themes.

From my understanding of the MSDN documentation this should be doing what I want -- but it's not.

The size of the client area of the form is the size of the form excluding the borders and the title bar.

Sample code here:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        this.ClientSize = new Size(800, 600);
    }
}

What gives? I noticed in the comments of an answer to another question that this is happening to someone else. Is there any way I can set the size of the client area reliably?

Community
  • 1
  • 1
Zack The Human
  • 8,373
  • 7
  • 39
  • 60
  • 1
    I just tried that code (on VS2008, Win7) and it performs correctly without any extra pixels (measured on a screenshot). Perhaps the particular theme you use has invisible parts that are counted as borders? – Max Shawabkeh Jan 22 '10 at 03:01
  • 1
    Is there a max height and max width set on your form? Otherwise the size settings work pretty predictably. – Charles Prakash Dasari Jan 22 '10 at 03:02
  • Thanks for the suggestions. I tried both setting a max/min size as well as both the Windows XP and Windows Classic themes. I'm still seeing the form 4 pixels too small to the right and on the bottom. :( – Zack The Human Jan 22 '10 at 03:28

1 Answers1

1

As it turns out, my problem was not with the Form at all. The form has a System.Windows.Forms.WebBrowser control in it -- and that has a border. Since the WebBrowser control doesn't have any border property I didn't suspect it.

Zack The Human
  • 8,373
  • 7
  • 39
  • 60