Results 1 to 3 of 3

Thread: Creating icons

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    20

    Creating icons

    Does anyone know how to save a graphic as an icon file so I can use it as an icon in vb6?

    Thanks

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Creating icons

    There are a lot of of icon editor software programs and GIF programs that also save icons. Do a google and you should find a few.

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Creating icons

    Well there is one easy way of doing it. However it can only create one icon size in the ico resourse, like one 32x32 pixel icon, and only with 16 colors. If that's OK then add a picture box with the inner size of 32x32 pixels, the easiest way is to set the AutoSize property to True and load a 32x32 pixel icon inside it. Then remove that icon. You now have a picture box of the correct size. Now also add an ImageList control to the Form and a CommandButton and the Common Dialog Control. Right click the ImageList control and select Properties. Set the size to 32 x 32.

    I'm going to assume you use the origional names for all of these controls. Now in the Command1_Click event use this code:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim pic As StdPicture
    3.    
    4.     Picture1.AutoSize = False
    5.     Picture1.AutoRedraw = True
    6.     Picture1.ScaleMode = vbPixels
    7.     Picture1.BackColor = vbRed
    8.     Picture1.Cls
    9.     Picture1.Picture = LoadPicture()
    10.     On Error Resume Next
    11.     With CommonDialog1
    12.         .CancelError = True
    13.         .Filter = "Bitmaps|*.bmp"
    14.         .DefaultExt = "bmp"
    15.         .Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
    16.         .DialogTitle = "Pick a small bitmap (size 32x32)"
    17.         .ShowOpen
    18.         If Err.Number = cdlCancel Then
    19.             Exit Sub
    20.         End If
    21.         Set pic = LoadPicture(.FileName)
    22.         Picture1.PaintPicture pic, 0, 0, 32, 32, , , , , vbSrcCopy
    23.         ImageList1.ListImages.Clear
    24.         ImageList1.UseMaskColor = True
    25.         ImageList1.MaskColor = vbRed
    26.         ImageList1.ListImages.Add Picture:=Picture1.Image
    27.         Picture1.Cls
    28.         .Filter = "Icons|*.ico"
    29.         .DefaultExt = "ico"
    30.         .Flags = cdlOFNOverwritePrompt + cdlOFNHideReadOnly + cdlOFNPathMustExist
    31.         .DialogTitle = "Save icon"
    32.         .ShowSave
    33.         If Err.Number = cdlCancel Then
    34.             Exit Sub
    35.         End If
    36.         Picture1.Cls
    37.         Picture1.Picture = ImageList1.ListImages(1).ExtractIcon
    38.         SavePicture Picture1.Picture, .FileName
    39.     End With
    40.     MsgBox "Icon saved", vbInformation
    41. End Sub
    This code will prompt you to open a small bitmap file that it will convert to an icon. After you have selected a bitmap, it will then prompt you for the name you want to use to save the icon.

    So to create an icon you simply create a BMP file in for example MS Paint and load it in this program. You can also use this as a base for a simple Icon Editor.

    If you want to a more advanced icon you need to use DIB sections. Do a search on http://www.vbaccelerator.com that has an icon editor control and also several articles on the subject.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width