C# – .NET Compact Framework 2.0 AutoSize Label

ccustom-controlswindows-mobile

I trying to make a Control that inherits from System.Windows.Form.Label that can resize to fit its text.

I'm trying to override OnTextChanged method to use System.Drawing.Graphics.MeasureString to know the new size of the control, but I don't know how to obtain Graphics on OnTextChanged method?

Any advice?

Thank you!

Best Answer

Try the Control.CreateGraphics method. The documentation says it's supported on the compact framework.

Graphics graphics = myLabel.CreateGraphics();