简体   繁体   English

.NET Compact Framework 2.0 AutoSize标签

[英].NET Compact Framework 2.0 AutoSize Label

I trying to make a Control that inherits from System.Windows.Form.Label that can resize to fit its text. 我试图制作一个从System.Windows.Form.Label继承的控件,该控件可以调整大小以适合其文本。

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? 我试图重写OnTextChanged方法以使用System.Drawing.Graphics.MeasureString来知道控件的新大小,但是我不知道如何在OnTextChanged方法上获取Graphics?

Any advice? 有什么建议吗?

Thank you! 谢谢!

Try the Control.CreateGraphics method. 尝试使用Control.CreateGraphics方法。 The documentation says it's supported on the compact framework. 该文档说它在紧凑框架上受支持。

Graphics graphics = myLabel.CreateGraphics();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM