?? Setting the ClientRectangle in a Custom Control ??

  • Thread starter Thread starter Tom Baxter
  • Start date Start date
T

Tom Baxter

Hi everyone,

I'm having a hard time figuring out how to set the ClientRectangle in a
custom control I'm writing. Since ClientRectangle has no setter property I
cannot change it directly.

The idea is that inheritors of this custom control should be limited to
drawing in the client portion of the control. As it is now, the entire
control surface is the client rectangle. I want the client rectangle to be a
small portion of the control.

Thanks
 
When you mention the client rectangle in this way you imply that the control
has a specific non-client area for which you will be responsible but which
the end-user will have litle or no control over. This is used for controls
that have a styled border or other decoration.

To set the client and non-client areas you need to override WndProc and
handle the various WM_NCxxx messages.

WM_NCCALCSIZE will enable you to set the client and non client sizes
WM_NCHITTEST enables testing the mouse in the non client area
WM_NCPAINT enables you to paint the bodrer or decoration

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Bob Powell said:
When you mention the client rectangle in this way you imply that the
control
has a specific non-client area for which you will be responsible but which
the end-user will have litle or no control over. This is used for controls
that have a styled border or other decoration.

To set the client and non-client areas you need to override WndProc and
handle the various WM_NCxxx messages.

WM_NCCALCSIZE will enable you to set the client and non client sizes
WM_NCHITTEST enables testing the mouse in the non client area
WM_NCPAINT enables you to paint the bodrer or decoration

Thanks, Bob. This is just what I needed to know.
 
Back
Top