• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

Change form's icon

In a VB4 programm, I want the form's icon to be changed according to the day of the month.
For example: I have 31 different icons (ico) and in the 1st day of a month the icon1 should be loaded. If the program runs the 2nd day of the month the icon2 ......and so on.
How could I do it?
Where must theese ico files be stored?

1 Solution
Anthony PerkinsCommented:
There are many ways to skin this cat, here is one:

Form1.Icon = LoadPicture("C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Arrows\ARW01DN.ICO")

One way ..

To assign an icon to a form, set the return value of the LoadPicture function to the Icon property of the Form object:

Set Form1.Icon = LoadPicture("MYICON.ICO")


In the load event of the form..

If Month = 01 then
 Set Form1.Icon = LoadPicture("MYICON1.ICO")

If Month = 02 then
 Set Form1.Icon = LoadPicture("MYICON2.ICO")

Or use a Case statement to achieve the same.

You can store the Icon file in a specific folder, perhaps where ever the .exe is run from etc..


Anthony PerkinsCommented:
A better approach is to use a Resource file for all your icons.  They get compiled in the EXE and you no longer have to worry about where all 31 icons are to be found.

The code is very simple (assuming that the Icons are stored as 101 to 131):

Private Sub Form_Load()

Form1.Icon = LoadResPicture(100 + Month(Date), vbResIcon)

End Sub

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

I don't know if you have ressources. If so, you can add your icon in the ressource file. You add each icon in the right order: myicon.ico to be displayed the first (position 100 in the ressource), Myicon2.ico to be displayed the second (position 1001 in the ressources), ...

than you call them
dim I as integer

i=100 + month - 1
set form1.icon=loadrespicture(i,vbresicon)
giannAuthor Commented:
Thanks all of you!
The answer of lyonst is simple and I could use it.
But the next 2 answers (acperkins, xThorx)look more serius.
The problem is that I have no idea how to make a resource file.
So let me wait for some more explanation.
Anthony PerkinsCommented:
Follow these steps:
1. Select the "Add-Ins" | "Add-In Manager" menu.
2. Select "VB 6 Resource Editor"
3. Check "Loaded/Unloaded".  Optionally "Load On Startup".
4. Click OK
5. Select the "Project" | "Add New Resource File" menu
6. Create a new Resource.
7. In the Project Explorer double click on the new Resource file (under Related Documents).
8. Click on the "Add Icon ..." icon.
9. Add an icon.
10. Repeat until finished.

Note:  If in Step 2 you do not see the VB6 Resource Editor, it is because it has not been installed.  If this is the case I suggest using LoadPicture("filename.ico"), like I suggested in my first comment.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now