Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Icon for OCX file 2

Status
Not open for further replies.

HyperEngineer

Programmer
May 8, 2002
190
US
I have a VB project that creates an OCX file. The icon associated with the file is the standard. Looks like two gears. However, I want to use my own. What I have done so far is, since I can't seem to be able to change the icon on the User Control, I have added a form and changed its icon to what I want. In the Project->Project1 Properties->Make->Application Icon, I selected the form with the desired icon. When I Make the .OCX file it still has the default icon. Plus, when I put the control on another VB project, it is blank. Just a grey rectangle with no picture at all. What do I have to do to get an icon or other picture to show up on the ocx file and the control in the toolbox for VB. I'm using VB 6.0.

HyperEngineer
If it ain't broke, it probably needs improvement.
 
Open the OCX probject in VB.
Under UserControls, there will be the name of your control. Click it.
In the properties window, you will find, 'ToolboxBitmap'.

Set this image, now when you compile, it should have that as the image instead of the default.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
George,

That worked for the toolbox. But I had to put the same picture in the Picture property to get a graphic for the control on a form. Thanks.

HyperEngineer
If it ain't broke, it probably needs improvement.
 
Eventhough I only gave you 1/2 the solution, I'm glad that I was able to help.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 

I know that i'm late, but a few notes about usercontrols and their various pictures/icons.

1. ToolboxBitmap:
This must 16 pixels wide and 15 pixels high.
The bottom left pixel sets the transparent color.

2. Picture:
I always use the following code when creating a usercontrol which is invisible at runtime (like the timer or winsock controls)

Code:
Private Sub UserControl_Initialize()
    UserControl_Resize
End Sub

Private Sub UserControl_Resize()
    With UserControl
        .Width = .ScaleX(.Picture.Width, vbHimetric, vbTwips)
        .Height = .ScaleY(.Picture.Height, vbHimetric, vbTwips)
    End With
End Sub

This ensures that the usercontrol is always matched in size to the picture, even if you change the picture.

3. Custom Icon:
If you want "OCX" files to show a custom icon in Windows Explorer, you need to add an icon to the project, and modify the registry.

a. Open the Resource Editor and add your icon.
b. Save the res file.
c. Compile the project.

Copy the following to notepad and save as "ocxicon.reg"

Code:
REGEDIT4

[HKEY_CLASSES_ROOT\.ocx]
@="ocxfile"

[HKEY_CLASSES_ROOT\ocxfile\DefaultIcon]
@="%1"

Double-click the file to complete.

Note 1: A registry file should always have 2 blank lines at the end.
Note 2: You may need to reboot to update the icon cache in Windows.
Note 3: All "ocx" files will now display their own icon if they have one. The drawback here is that if an ocx file doesn't contain any icons, it will display the default Windows icon for an unknown filetype.

Cheers.

Be good. If you can't, don't get caught!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top