Click here to Skip to main content
15,512,565 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using Visual Studio 2019 v 16.6.2 with Frame Work 4.7.2 on a Windows 7 64 bit machine

I am coding in visual basic NOT C#
Icon is 32X32 with 32 bit depth created with GreenFish icon maker
I know how to set the icon for a form using the properties setting. My concern here is that this process will not find the icon when I create an EXE file. Which I have not tested making an EXE file


So I found this process Right Click Project > Properties > Application > Icon ComboBox > Browse Select the icon Which is on my Desktop

When I did this VS added the icon to my project as q.ico Perhaps Great

But when I run the project all I see is the default icon NOT GREAT

So to test a little more I tried to add a icon to a button this maneuver resulted in a folder being created named Resources with the icon inside the folder

Upon running the project yep the button had the icon on the button


Keeping in mind my real goal here is to have a self-contained application that will run on any Windows computer

The questions are

Why is the titlebar not displaying the new icon in the project?

Will the created folder "Resources" be included in the EXE file?


What I have tried:

VB
Public Class frmOne
    Private Sub frmOne_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        tbLoad.Text = "I Loaded"
    End Sub

    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
        Application.Exit()
    End Sub
Posted
Updated 22-Jun-20 12:34pm
v2

Hi,

a Form has an Icon property, defining which icon may be shown at the lefthand side of a Form's title bar.

an application has it's own icon, which you can specify through the project's property page; right-click the project in Solution Explorer, choose Application tab, and browse for the file where it says icon:...

Quite often you want your main form (or even all forms) of an app to show the same icon as your app itself (e.g. in the task bar), an yes that takes two separate operations.

:)
 
Share this answer
 
Comments
Choroid 22-Jun-20 16:21pm    
Luc I did that Right Click Project > Properties > Application > Browse I now have the icon in the ill named folder Resources selected it and all I see is the default icon
Luc Pattyn 22-Jun-20 16:42pm    
Icons have always been a bit tricky. They evolved from a single image to a set of different sizes and color depths. The one used by the taskbar button will be different from the one used by the desktop Explorer (which itself depends on some choices about icon sizes on the desktop) etc.

I tend to provide an icon file that only holds a 32*32 pixel icon and I use it for both the forms (in WinForms) and the apps, normally that works well for me. If you feel a need to stuff multiple sizes/depths in one ico, make very sure they all look pretty much the same, or you will be in for surprises. What you certainly should not do is take an existing ico and replace one of its images but not all of them.

AFAIK the folder the ico file is in does not really matter; what may be relevant is the properties you give that ico file in Solution Explorer; I tend to use either "content" or "embedded resource" (Not sure what it all means for icons), and "do not copy".

Suggestion: try a few things, if all else fails try again with an icon file from a different source.

:)
Choroid 22-Jun-20 16:30pm    
Luc Pattyn I also have the Maximize Box set to True as I was told this could not be false Why is it so Impossible to manage the titlebar? I have search for 2 days looking for the name of the items in the titlebar
Luc Pattyn 22-Jun-20 16:46pm    
Don't ask me why Microsoft did what they did, I don't know, I'm not sure they do either. :)

The way I go about that is: use Visual Studio, open a Form in View Designer, then choose properties, and one by one toggle everything boolean and watch what happens.

One of the strangest things in Windows land is they provide a lot of documentation in textual form but most often refuse to provide images that would make things much clearer. Well, in the end you learn to live with the way it is...

:)
Choroid 22-Jun-20 16:52pm    
Luc I did try embedded resource no luck it has always been set to content I have even tried a 16X16 with 8 bit depth no luck Is it possible to send me one of your icons I guess I need to post an e-mail address in the comments then delete once you have it
I just tried the same thing and it failed as you say. However, I then double clicked the form and changed the icon in the form properties, and it showed the correct icon.

As to your second question, all resources that are used in building the application are built into the final executable file. So the resources always go with the application.
 
Share this answer
 
Comments
Choroid 22-Jun-20 16:15pm    
Richard I might not have been clear the folder I am talking about is one I create named Resources This was a bad choice for the name As I am not talking about any folder under Resources.resx I should have named the folder Images
Richard MacCutchan 23-Jun-20 2:45am    
Open the project's Properties page, go to the Resources tab and add the icon there. That will ensure it is part of the final executable.
Maciej Los 23-Jun-20 3:23am    
5ed!
Well this is a kick in the pants

A 7 year old post on SO

[^] Link to SO


Code I used
Public Sub SetIcon()
    InitializeComponent()
    Icon = Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetExecutingAssembly().Location)
End Sub


It uses the icon set under Application Browse
YES Microsoft need a few novices to write a How to Series
ONLY issue is every 3 months the Series would be outdated
 
Share this answer
 
Comments
Choroid 22-Jun-20 18:38pm    
Luc
For any one who sees Solution 3 I only works on a project with one form
If you have multiple forms the code prevents navigation to other forms
NOT A SOLUTION If someone would like to explain this failure please feel free
Luc Pattyn 22-Jun-20 20:32pm    
That would work for any form, as long as you put a single line in its constructor (or its Load handler):

Icon = Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetExecutingAssembly().Location)

which basically says: set this form's icon to the icon associated with the file whose path I'm giving you, which is actually your own EXE path. Extracting an icon that way is rather expensive.

Two ways to improve:

1. a simpler line would be

Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath)

which avoids reflection but still scrutinizes the file looking for the app icon.

2. If you set both app icon and mainform icon to the icon you want then it is easy and inexpensive to copy that icon from mainform to any other form within the app.

And that is what I usually do by defining a "BaseForm" that holds all my form preferences (sizing behavior, icon, styles, ...) from which I inherit all other forms.

:)

PS: I hope you found in one of the older replies my confirmation on older Windows versions always showing the app icon in the taskbar.
Choroid 23-Jun-20 10:59am    
Luc Just tested and it works I can not edit my solution which I find frustrating
My solution while it worked was code I did not understand OH the joy of learning
VB.Net has its own very useful idea of PATHS coming from NetBeans it was easy as long
as the Object was in the Project you could find it Guess it is the same for
VB.Net just learning what "My" does has been an eye opener Thanks

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