title: Can you get the size of the visible area of a clipped control?
body: <p>Is there a way to get the size of the visible portion of a clipped control in WinForms? </p>
  
  <p>A very simple example: place a control on a form and make the form width smaller than the control width. How do you get the width of the visible area of the control? In this case you can use the form's ClientSize, but it's not always that simple.</p>
  
  <p>A more complex (and real) example: I have a label with AutoSize set to true, and it can to grow beyond the width of its containing control, causing it to be clipped. When this happens I need to know. It's not as simple as comparing the width of the label with the width of its container, since the container may also have AutoSize = true and also be clipped.</p>
  
  <p>Currently my approach is to walk up the container tree until I find a container that has AutoSize = false, and get its width. I also have to take the padding of each container into account. But this only considers a control being clipped by its container, or its container's container, etc. It wouldn't work if the control in question, or any of the containers, are being clipped by a sibling control with a higher Z-order. And I suspect there are other ways to easily break this approach.</p>
  
  <p>Changing the label AutoSize to false isn't an option. The label is on a UserControl which is set to AutoSize so that when the label grows, the UserControl grows with it. Getting this to work without using AutoSize is painful.</p>
  
  <p>Things I've tried using, unsuccessfully:</p>
  
  <p><code>Control.ClientSize</code>, <code>Control.ClientRectangle</code>, <code>Control.PreferredSize</code>, <code>Control.CreateGraphics().VisibleClipBounds</code>.</p>
  
  <p>I've played with the Graphics class a little but I'm in over my head there. <code>Graphics.VisibleClipBounds</code> sounded promising but always seems to return the same as the other size properties mentioned.</p>
  
  <p>This pertains specifically to WinForms. I would be be happy with a p/invoke solution if that's all there is.</p>
  
  <p>I did do an exhaustive search before posting. None of the similar questions are helpful.</p>