Click here to Skip to main content
15,911,132 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
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.
Posted
Updated 27-Feb-11 11:59am
v2

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.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 27-Feb-11 19:23pm    
If your assumption is correct, this is good, my 5.
I did not even think about it, as OP says just about user control, so I tried to explain how to render the image.
--SA
There is no "assign icon". This is User control; you're fully responsible for its graphical rendering.

You can override its OnPaint method and draw any graphics on its surface using Graphics object passed in its parameter of the type PaintEventArg.
(Don't create a Graphics object, it's a common mistake.) Create an Icon property for your control and don't forget to check if it is null in your implementation of OnPaint. You may also want (and usually need to) to adjust layout of all of the children of your UserControl depending on the size of the icon supplied by the user.

I also suggest using Bitmap instead of Icon. Icons are mostly designed to work with Shell API, so you only need an icon to represent your application and forms, not controls.

—SA
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 27-Feb-11 18:53pm    
Anonymous coward keeps voting 1. Ha! This is funny.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900