Win forms icon of exe - c#

I'd like to set icon of exe file, after publishing windows forms application on C# in Visual Studio.
What i do: Project->properties->icon->browse and setting the file.ico
rebuilding a project, publishing but nothing happends. published app still has deafult icon. What im doing wrong?
UPD: yes, i have read guide by microsoft and tried to add icon as resource. It takes no effect. (icon is valid and i also tried to use default generated icon from resource)
UPD2: I did everything correctly, but i tought that setup.exe file will have the icon. This where i was wrong. Programm will crieate icon, in folder with other programms.

Your .exe can't find the directory of .ico file. To fix this you can add .ico file in Resources -> Add Resource. Select the icon in Application -> Resources -> Icon and manifest -> select your icon.

Related

How do I force Visual Studio 2019 to generate a .deploy file for an icon for ClickOnce deployment/install

I'm running into a problem publishing/installing a ClickOnce application being built in C# in Visual Studio 2019. The application is being built using .NET Core 3.1 and WPF.
I have an icon I am using for the application that is included in the project with the filename "loader.ico". The ClickOnce manifest is calling out for loader.ico, but the required Loader.ico.deploy file is not being generated when publishing, which is throwing an exception when trying to run the setup.exe to install the application to a client PC (actual filepaths have been replaced with [Path]:
+ Downloading file:///[Path]/x64/ClickOnce/Application Files/.NET Bootloader_1_0_0_4/loader.ico.deploy did not succeed.
+ Could not find file '[Path]\x64\ClickOnce\Application Files\.NET Bootloader_1_0_0_4\loader.ico.deploy'.
I have attempted a few things using what information on the problem I could find:
I set the Build Action for loader.ico to Content and set Copy to Output Directory to Copy Always. I also set the "Settings>Application Files" setting for loader.ico to Include. This has no effect on the resulting Publish, and no loader.ico.deploy file is generated.
I also receive the following in the output window when publishing:
Unable to apply publish properties for item "loader.ico"
I have also tried excluding loader.ico from the "Application Files", but this does not remove the reference in the .manifest file.
So now I am at a bit of a loss. I don't know why it would demand a .deploy file for the icon (I'd think it would just be embedded? No need for a separate icon file?). I can't seem to get the ClickOnce publishing process to generate the required loader.ico.deploy file, and I can't seem to get the manifest to remove the reference to it. What settings could be used to force the generation of this .deploy file (or force the manifest to not reference it)?
I had the same problem your application .ico file causes this error so you have to change its properties setting to Build Action: Content and Copy To Output Directory: Copy always.
hope it works
I can confirm from my very own experience how frustrating this is. I have tried anything and everything.
For the time being - until this issue is sorted - I am suggesting that you manually add the .ico file to the Apllication_1_0_0_x folder and appending '.deploy' at the very end.
So file will look like 'my-icon.ico.deploy'.
It works. Tried and tested.
In my case it helped:
Publish -> Show all (Settings current project) -> Settings -> Application Files -> (Show all files):
Find ico file, select publish status to Include | (Required) | Include.
From now on, the ICO file will be added when publishing
Additionally to the icon loading problem that I initially "solved" with Avrohom's method, I faced some issue with WebView2 not working / being loaded.
Both of these problems stopped when I disabled the click once publishing profile (.pubxml) option for producing a single EXE file:
<PublishSingleFile>False</PublishSingleFile>
Tested with .NET6, Visual Studio 2022

How to change my App's icon in Xamarin.Forms using Visual Studio?

I'm new to Xamarin.Forms and I am finding it impossible to change the application's icon for my app.
I used a cross-platform template in VS2017. I changed all the icon files in #mipmap-XXXX. When I run in the emulator the app icon changes but not on my device.
Does anyone have a proven method for getting this working. I'm sure it's possible but I can't find any information that helps.
If you're creating projects using the newest VS/Xamarin update, you should notice a folder in the Android project (under Resources) called mipmap-anydpi-v26, or similar. In this folder, you will find two XML files: icon.xml and icon_round.xml. If you open these files, you'll notice that they reference :
launcher_foreground - your icon image.
launcher_background - background color of your icon, mainly used for round icons.
When you are assigning the app icon and you reference icon, you are actually referencing the XML file, not the images. The XML file then retrieves the correct image size from the other mipmap folders.
Thanks both for your comments. However, neither completely solved the problem. In the end I looked in the file system and removed all icon.png images. I cleaned and rebuilt the app and nothing changed when I deployed it. I then repeated the above on all the launcher_foreground.png files and replaced them with appropriately sized ones. Now my application icon is what I wanted.
I seems that even though there is a icon.png file in each of the mipmap-xxxx folders, it is the launcher_foreground.png file that holds the application icon.

How do I include an icon once that can be used for both the executable and a form?

I'm trying to use a single .ico file (with multiple sizes) for both the Application executable and a form inside the application, without including the icon in the executable twice.
I noticed this because my app (without icons) is 600KB compiled, and the icon is 300KB, but when I use both the app increases to 1200KB compiled, indicating it's being embedded twice.
Here's what I've tried:
(1) Pick icon files using UI
Go to Application Properties > Application > Resources > Icon and use the "..." button to pick MyIcon.ico file.
Compiled exe is now 900KB
Go to Form Properties > Icon and use "..." button to choose MyIcon.ico file.
Compiled exe is now 1200KB
(2) Use resource
Go to Application Properties > Resources > Icons > Add existing file and pick MyIcon.ico file
In form constructor, add: this.Icon = Properties.Resources.MyIcon;
Compiled exe is now 900KB
Go to Application Properties > Application > Resources > Icon, and choose Resources\MyIcon.ico (which is listed in the drop-down)
Compiled exe is now 1200KB
Clearly, it's still including the file a second time, not referencing an embedded resource.
(3) Use Icon.ExtractAssociatedIcon()
Go to Application Properties > Application > Resources > Icon and use the "..." button to pick MyIcon.ico file.
Compiled exe is now 900KB
In form constructor, add this.Icon = Icon.ExtractAssociatedIcon(AppDomain.CurrentDomain.FriendlyName);
Compiled exe is still 900KB, but icon is the generic "exe" icon from Windows, not my application's icon
Before I go deeper into this, am I missing something obvious? Is there a standard way to do this? Am I just not using Icon.ExtractAssociatedIcon() properly?
I'm sorry, this is my oversight. Method (3) does actually work.
I was running this from the VisualStudio debugger, but didn't notice the .vshost.exe file gets a different icon -- which is what was showing up in the form.
When the compiled exe is used directly, it works fine.
After adding the necessary icon into the project you have to do 2 things:
Select Form and in the "Properties" select that icon in the "Icon" property.
Go to the Properties of the project and in the Icon field select the same icon.
When you build the project you will see necessary icon everywhere.
UPDATE:
Sorry not full answer and here we go:
You were right, it creates it twice, first one is ico file itself, the second one is base64 string in Form.resx file that generates when you add ico in the first step. So, how do fix it
First of all go to InitializeComponent() method, fine this.Icon string and change it to the following
this.Icon = new Icon(Path.GetDirectoryName(Application.ExecutablePath) + "../../../[YOUR ICO FILE NAME].ico");
, then delete autogenerated Form.resx file.
Icon object here is System.Drawing.Icon. The file name I set for example, as you see it is the ico which is next to *.sln file. In the real case, it will be without going to parent folders.

Application taskbar icon set wrong when in a specific path - where is this set?

I'm working on an application (C#/WPF) and when it is installed in the Program Files folder and run the icon on the taskbar shows up wrongly as this;
But if I rename or copy into another folder the correct icon appears when run. It seems like an icon is set for this file in this path. I've had a look through the registry but with no luck and also cleared the icon cache.
Any ideas?
That is a symptom of the icon being cached and the cache not being refreshed. Normally a restart fixes the problem.
I had the same problem, and fixed it through the setup project.
In Visual Studio:
right click the setup project.
Select View -> File System.
Display properties for the shortcut for your application (typically
under Users Program Menu).
The Shortcut will have a property call Icon. Set that to the EXE of your application, or set it to an icon in your setup package.
Build the setup project, and then re-install.

WinForm C# programatically embedding an image in resx

I am using VS 2005 for a windows application.
There have been code added in the UI form in past such that the form does not open in designer anymore.
I now have to add an icon in an System.Windows.Forms.ImageList.
Right now it simply adds images from the resource file in the InitilizedComponent() in the following way which I believe was originally generated by the designer.
this.MyimageListToolbar.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("MyimageListToolbar.ImageStream")));
In order to add my new icon I can simply say
Icon myIcon = new Icon(#"mypath/myicon.ico");
this.imgLstToolbar.Images.Add(myIcon);
but the problem then is that I would have to include this ico file in the setup project so it gets copied when this sofware is installed. This is not desirable. All other images added on the imagelist tool bar are not copied when the application is installed.
Is there a way I can programatically add the icon or add the icon without using the designer and still have it included in the resource file so I dont have to copy the ico file in order to run the exe.
Thanks,
You can add the icon to the "resource file" like so..
Right click on the folder "Resources" -> "Add" -> "Existing item..."

Categories

Resources