You are here : Blog
Search_Blog Minimaliseren

KHSW Soft Blog Minimaliseren
Mar 8

Written by: Ken Huysmans
2006-03-08T11:16:56 

 

 
You just have finished your application, the only thing you need is an icon. You don't have icons on your machine and you don't have the graphical skills to create one. But... you have an image on your PC or you found one on Google (watch out for copyrights!) that could be used, too bad it's not in .ico format.

But since you're a .NET-coder, you can create an application to convert an image to an icon in less then one minute!
Have a look at this demo application.
  • Create a new Windows Application
  • Set the value of the AllowDrop property of the form to True
  • Add this code to the DragEnter event of the form

Private Sub Form1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub

  • Add code to the DragDrop event of the form

Private Sub Form1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragDrop
Dim arr As Array = DirectCast(e.Data.GetData(DataFormats.FileDrop), Array)
For i As Integer = 0 To arr.Length - 1
CreateIcon(Convert.ToString(arr.GetValue(i)))
Next
End Sub

  • Create the CreateIcon procedure

Private Sub CreateIcon(ByVal bitmapName As String)
Try
Dim fi As New System.IO.FileInfo(bitmapName)
Dim bmp As New Bitmap(fi.FullName)
Dim sw As System.IO.StreamWriter = System.IO.File.CreateText(fi.FullName.Replace(fi.Extension, ".ico"))
Icon.FromHandle(bmp.GetHicon).Save(sw.BaseStream)
sw.Close()
Catch ex As Exception
System.Diagnostics.Debug.WriteLine(ex)
End Try
End Sub

That's all... Just drop an image on your form and the icon will be created.

 

 

Tags:

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Annuleren 


Copyright 2007 by KHSW Soft BVBA
PrivacybeleidGebruiksovereenkomst