Edit icon with specific resolution programmatically

In my this.Icon application, I can change the taskbar icon using this.Icon , but also change the application icon in the header.

this is how i edit the icon now:

 public static Icon GetIcon(string text) { //Create bitmap, kind of canvas Bitmap bitmap = new Bitmap(32, 32); Icon icon = new Icon(@"<icon-location>"); System.Drawing.Font drawFont = new System.Drawing.Font("Calibri", 12, FontStyle.Bold); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Orange); System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap); graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel; graphics.DrawIcon(icon, 0, 0); graphics.DrawString(text, drawFont, drawBrush, 20, 15); Icon createdIcon = Icon.FromHandle(bitmap.GetHicon()); drawFont.Dispose(); drawBrush.Dispose(); graphics.Dispose(); bitmap.Dispose(); return createdIcon; } 

This was not a problem until the requirements have changed, and now you only need to change the taskbar icon without changing the title icon (upper left window of the application).

After some searching, I came across this answer , which basically claims that different permissions are used to display the icon in different places. The โ€œGreenfish Icon Editor Proโ€ mentioned in this answer works well, but my changes must be made at runtime, as it is used as a notification method to notify the user of the number of unread notifications so that it doesn't edit once.

I understand that I need to change the 64x64 icon to achieve my goal, but for now, all I can do is change the icon all together.

Anyway, can I edit the GetIcon () function to edit a specific icon resolution? (or at least suggesting an alternative method would be greatly appreciated)

+4
source share
1 answer

What are you asking:

How to programmatically create a multi-icon?

The standard Icon .NET class does not provide the ability to do this just because .NET does not have an ICON encoder, see this article for proof.

By the way, you can create multiIcon just by creating your own encoder, fortunately you do not need to do this because there are some good Samaritans who have already done this. Some link that might be helpful:

Hope this helps.

+2
source

Source: https://habr.com/ru/post/1501256/


All Articles