如何为用户控件创建图标 [英] how can create an Icon for an user control
本文介绍了如何为用户控件创建图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我已经创建了一个用户控件,我想为其分配一个图标.我尝试从SolutionExplorer/属性/应用程序选项卡/图标和清单进行尝试,但没有得到任何正确的结果.
是否有任何方法可以做到这一点?谁可以帮助我?
谢谢.
Hello
I have created an user control and I want to assign it an icon. I try it from SolutionExplorer / properties /application tab / icon and manifest but I didn''t get any correct result.
Do exist any way to do it? Who can help me?
Thanks.
推荐答案
如果您是说要在控件的工具箱中显示一个图标,则 ^ ]可能会有所帮助.
您可能还会找到此 [ ^ ]文章很有用.它的解释要比Microsoft页面更清楚.
If you mean an icon to appear in the toolbox for your control, then this[^] might help.
You might also find this[^] article useful. It explains a little more clearly than the Microsoft page.
没有分配图标".这是用户控件;您要对其图形呈现完全负责.
您可以覆盖其OnPaint
方法,并使用在其PaintEventArg
类型参数中传递的Graphics
对象在其表面上绘制任何图形.
(不要创建Graphics
对象,这是一个常见错误.)为控件创建Icon
属性,并且不要忘记在实现OnPaint
的过程中检查它是否为null
. .您可能还希望(并且通常需要)根据用户提供的图标的大小来调整UserControl
所有子级的布局.
我还建议使用Bitmap
而不是Icon
.图标主要是为了与Shell API配合使用而设计的,因此您只需要一个图标即可代表您的应用程序和表单,而不是控件.
—SA
There is no "assign icon". This is User control; you''re fully responsible for its graphical rendering.
You can override itsOnPaint
method and draw any graphics on its surface usingGraphics
object passed in its parameter of the typePaintEventArg
.
(Don''t create aGraphics
object, it''s a common mistake.) Create anIcon
property for your control and don''t forget to check if it isnull
in your implementation ofOnPaint
. You may also want (and usually need to) to adjust layout of all of the children of yourUserControl
depending on the size of the icon supplied by the user.
I also suggest usingBitmap
instead ofIcon
. Icons are mostly designed to work with Shell API, so you only need an icon to represent your application and forms, not controls.
—SA
这篇关于如何为用户控件创建图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文