简体   繁体   English

在 UserControl 中使用 Label 或 DrawString

[英]Use Label or DrawString in UserControl

I am writing my own control that will contain a panel with text, images and other media.我正在编写自己的控件,该控件将包含一个带有文本、图像和其他媒体的面板。 What is the best way to render the text and images.呈现文本和图像的最佳方式是什么。 The control may contain long texts and many images.该控件可能包含长文本和许多图像。
Should I add the text as labels and images as PictureBox or should I use the DrawString and DrawImage methods to render the text and images?我应该添加文本作为标签和图像作为 PictureBox 还是应该使用 DrawString 和 DrawImage 方法来呈现文本和图像?
What's the best way to do this?做到这一点的最佳方法是什么?

If you use labels, then you get all the labelly goodness for free.如果您使用标签,那么您将免费获得所有标签的优点。

If you use DrawString, then it'll probably be (a little bit) faster, but it's a lot more complicated if you need to deal with things like the text changing.如果您使用 DrawString,那么它可能会(一点点)更快,但是如果您需要处理诸如文本更改之类的事情,它会复杂得多。

The OnPaint handler is a always a tricky one to write, and invalidating the client area is tricky to do efficiently. OnPaint 处理程序编写起来总是很棘手,而有效地使客户区无效也很棘手。

Why not let the labels handle it all for you?为什么不让标签为您处理这一切?

I would use DrawString and DrawImage - you have less resources to worry about, but with added complexity.我会使用 DrawString 和 DrawImage - 您需要担心的资源较少,但会增加复杂性。

I don't think it's that bad drawing your own strings and images once you get into it.我认为一旦你开始画自己的字符串和图像并没有那么糟糕。

This is a nice introduction to it:这是一个很好的介绍:

https://web.archive.org/web/20150116060854/http://bobpowell.net/ https://web.archive.org/web/20150116060854/http://bobpowell.net/

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

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