Windows Develop Bookmark and Share   
 index > Windows Forms General > change the Icon of a UserControl.?
 

change the Icon of a UserControl.?

How to change the Icon of a UserControl.?

Normally, it appears in the ToolBar as something like a Purple color rounded flower.(Default)
How to change this.
I want to put a new Icon for that.!
Is it possible.
??

need help!

ugp  Friday, July 13, 2007 3:01 AM

Here is what I did:

  • Added a user control (named UserControl1) to a normal windows application project.
  • Added a bitmap (named UserControl1.bmp) to the same project.
  • Opened the bitmap for editing, resized it to16x16, colored it a little, then saved and closed it.
  • Clicked once on the bitmap in theSolution Explorer window, then changed the "Build Action" property in the properties window to "Embedded Resource".
  • Opened the code editor forthe user control, then added the following attribute info prior to the definition of my class:

[System.Drawing.ToolboxBitmap(typeof(UserControl1))]

  • - Built my application.

The icondid not automatically update in my toolbox after I did all that. So, I continued with this...

  • I right-clicked on my toolbox and selected "Choose Items...".
  • I scrolled through the list of .NET Framework Components until I found my UserControl1 in the list. I looked to see what directory it was pointing to and it was my "obj\Debug" folder.
  • I unchecked my UserControl1item in that list, then clicked the "OK" button.
  • My user control was removed from the toolbox.
  • I right-clicked on my toolbox againand selected "Choose Items...".
  • I clicked the "Browse" button and navigated to my "obj\debug" folder (for my project) and selected my application's executable in that directory.
  • I clicked all the "OK" buttons to get back to my project, and my icon updated.

I'm not saying or recommending that the last portion above is the way to do it... but that's how I did it to get it to work.

ARK88  Friday, July 13, 2007 5:59 AM

Here is what I did:

  • Added a user control (named UserControl1) to a normal windows application project.
  • Added a bitmap (named UserControl1.bmp) to the same project.
  • Opened the bitmap for editing, resized it to16x16, colored it a little, then saved and closed it.
  • Clicked once on the bitmap in theSolution Explorer window, then changed the "Build Action" property in the properties window to "Embedded Resource".
  • Opened the code editor forthe user control, then added the following attribute info prior to the definition of my class:

[System.Drawing.ToolboxBitmap(typeof(UserControl1))]

  • - Built my application.

The icondid not automatically update in my toolbox after I did all that. So, I continued with this...

  • I right-clicked on my toolbox and selected "Choose Items...".
  • I scrolled through the list of .NET Framework Components until I found my UserControl1 in the list. I looked to see what directory it was pointing to and it was my "obj\Debug" folder.
  • I unchecked my UserControl1item in that list, then clicked the "OK" button.
  • My user control was removed from the toolbox.
  • I right-clicked on my toolbox againand selected "Choose Items...".
  • I clicked the "Browse" button and navigated to my "obj\debug" folder (for my project) and selected my application's executable in that directory.
  • I clicked all the "OK" buttons to get back to my project, and my icon updated.

I'm not saying or recommending that the last portion above is the way to do it... but that's how I did it to get it to work.

ARK88  Friday, July 13, 2007 5:59 AM

Thanks ARK88

It works......

ugp  Friday, July 13, 2007 9:51 AM

but here the problem is....

when close and open the solution those icons are miss out. It shows the default Icons again.

Is there a way to show it permanently...?

need help!

ugp  Friday, July 13, 2007 11:51 AM
Seems to be more reliablewhen I built my user controlin a control library, then referenced that component... any chance that is a viable option for you? An additional benefit is that it would make your component reusable throughout your projects. Just a thought...
ARK88  Friday, July 13, 2007 12:59 PM

You can use google to search for other answers

Custom Search

More Threads

• Child and Parent Form
• GetFiles() with two search format
• Input redirection / Inconsistence between SPY++ messages / DefWndProc messages
• Ellipsis at design time on a winform - possible ?
• How to assign Empty Value to DateTimePicker?
• DoEvents in a Class Library
• create a report and print it?
• Application Scope Variables
• DataGridComboBoxColumn
• How to work with WindowsExplorer ContextMenu?