Change form's icon

Posted on 2003-02-26
Medium Priority
Last Modified: 2010-05-01
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?

Question by:giann
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 75

Expert Comment

by:Anthony Perkins
ID: 8026189
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")

LVL 15

Expert Comment

ID: 8026212
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..


LVL 75

Expert Comment

by:Anthony Perkins
ID: 8026241
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Expert Comment

ID: 8026273
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)

Author Comment

ID: 8026646
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.
LVL 75

Accepted Solution

Anthony Perkins earned 300 total points
ID: 8026975
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.


Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question