I'm makeing a program that mimics the desktop, i've got it all working but i'm only getting the lowest Resolution out from the icons.
I need to get all of the icons from files in a set path, these icons need to be the best they can (256x256).
I want to get Icon from files like .exe .lnk .url .txt .png . jpg
this is a Shortend Verstion what i have currently.(I remove all the part that don't have any affect on the icons)
Public Class Form1
Dim counter As Integer = 0
Dim IconArray(200) As PictureBox
Dim TitleArray(200) As Label
Dim linker(200) As String
Public Sub loading(sender As Object, e As EventArgs) Handles MyBase.Load
Apps_on_Screen.Items.AddRange(IO.Directory.GetFiles("C:\Users\Public\Desktop")) 'Gets All files on Desktop and adds them to listbox
Threading.Thread.Sleep(0) 'waits till all file have been got from desktop
Dim Icon_Position_X = 0, Icon_Position_Y = 5 'Sets the start X and Y for the Icons
Dim Title_Position_X = 0, Title_Position_Y = 55 'Sets the start X and Y for the Text under the Icons
For i As Integer = 0 To Apps_on_Screen.Items.Count - 1 'Loops for every item in listbox
Dim Icon As New PictureBox 'Creates new Picturebox
Icon.BackgroundImageLayout = ImageLayout.Zoom 'Changes it to zoom so the images fits
Icon.BackColor = Color.Transparent 'Makes Picturebox Transparent
Icon.Name = "Icon" & i 'Gives picturebox a name for a referance later
Icon.Size = New Size(78, 51) 'Sets the Picturebox a size
Icon.Location = New Point(Icon_Position_X, Icon_Position_Y) 'Sets the Pictureboxs X and Y
Me.Controls.Add(Icon) 'Adds picturebox to controls
IconArray(i) = Icon 'Adds picturebox to an Array for easyer use later
IconArray(i).BringToFront()
AddHandler Icon.DoubleClick, AddressOf Me.Start_Link 'Adds a Double click Handler for picturebox on A Sub
Icon_Position_Y += 101 'Changes the Y Postion on next Picturebox
If (Icon_Position_Y + 50) >= Screen.PrimaryScreen.WorkingArea.Height Then 'When the Picture box reaches the bottom of the sceen the Y Resets and The X Gets Increased
Icon_Position_Y = 5
Icon_Position_X += 78
End If
'Same as Above, But with a Label
Dim Title As New Label
Title.Name = "Title" & i
Title.Size = New Size(78, 51)
Title.Location = New Point(Title_Position_X, Title_Position_Y)
Title.ForeColor = Color.White
Title.BackColor = Color.Transparent
Title.TextAlign = ContentAlignment.TopCenter
Title.Font = New Font("Microsoft Sans Serif", 9)
Me.Controls.Add(Title)
TitleArray(i) = Title
Title.BringToFront()
AddHandler Title.DoubleClick, AddressOf Me.Start_Link
Title_Position_Y += 101
If Title_Position_Y >= Screen.PrimaryScreen.WorkingArea.Height Then
Title_Position_Y = 55
Title_Position_X += 78
End If
Next
Set_icons()
End Sub
Public Sub Set_icons()
'Most PC's have "This PC" on the Desktop
IconArray(0).BackgroundImage = Fake_Background.My.Resources.This_PC
TitleArray(0).Text = "This PC"
linker(0) = "C:\WINDOWS\explorer.exe"
counter = 1
For Each Item In Apps_on_Screen.Items 'loops for every item in listbox
Try 'Just here incase it crashes
linker(counter) = Item 'adds item to array to be use to start the programs
IconArray(counter).BackgroundImage = Icon.ExtractAssociatedIcon(Item).ToBitmap 'Gets a 32x32 icon from item then sets it as the icons background
Dim Extension = IO.Path.GetExtension(Item) 'Gets the extension from item, to be used later
Item = IO.Path.GetFileName(Item) 'Gets the Items name E.G Item = "C:\Users\Public\Desktop\Hi.txt" now item = "Hi.txt"
If Item = "desktop.ini" Then '"desktop.ini" Didn't want to work thats why i have the code at the top of this sub
counter -= 1
Else
Item = Item.Replace(Extension, "") 'Removes the extension from item E.G item = "Hi.txt" now item = "Hi"
TitleArray(counter).Text = Item 'Sets the display text for the item
'This part is how i Get the higher Res icons
Item = Item.Replace(" ", "-") 'Replaces " " with "-"
'I've got a bunch of images of icons in Resources
IconArray(counter).BackgroundImage = DirectCast(My.Resources.ResourceManager.GetObject(Item), Bitmap) 'Seaches for Item in Resources if its found its add set to the icons background
End If
Catch ex As Exception
End Try
counter += 1
Next
End Sub
Public Sub Start_Link(sender As Object, e As EventArgs)
'i don't know how to explane this
Dim start = 0
If sender.Name.Contains("Icon") Then start = Val(Replace(sender.Name, "Icon", ""))
If sender.Name.Contains("Title") Then start = Val(Replace(sender.Name, "Title", ""))
Try
Process.Start(linker(start))
Catch ex As Exception
If linker(start).Contains(" (x86)") Then 'some programs didn't want to work so i added this as a fix
linker(start) = Replace(linker(start), " (x86)", "")
Process.Start(linker(start))
End If
End Try
End Sub
End Class
This code only grabs the 32X32 size Images of icon to compair Desktop, In Program
Is there a way for me to get the best Resolution icon.
Can you post the code? as i've spent an hour just looking around following links, but it's all in c# and not to much help for me.
Thanks ~Gamer_sa22