Nun kommt die Form incl. des platzraubenden "Vom Windows Form Designer generierter Code", damit alle Steuerelemente richtig übernommen werden.
Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Vom Windows Form Designer generierter Code "
Public Sub New()
MyBase.New()
' Dieser Aufruf ist für den Windows Form-Designer erforderlich.
InitializeComponent()
' Initialisierungen nach dem Aufruf InitializeComponent() hinzufügen
End Sub
' Die Form überschreibt den Löschvorgang der Basisklasse, um Komponenten zu
' bereinigen.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
' Für Windows Form-Designer erforderlich
Private components As System.ComponentModel.IContainer
'HINWEIS: Die folgende Prozedur ist für den Windows Form-Designer
' erforderlich
'Sie kann mit dem Windows Form-Designer modifiziert werden.
'Verwenden Sie nicht den Code-Editor zur Bearbeitung.
Friend WithEvents pnlIcons As System.Windows.Forms.Panel
Friend WithEvents toolTip As System.Windows.Forms.ToolTip
Friend WithEvents cmdGo As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Me.cmdGo = New System.Windows.Forms.Button()
Me.pnlIcons = New System.Windows.Forms.Panel()
Me.toolTip = New System.Windows.Forms.ToolTip(Me.components)
Me.SuspendLayout()
'
'cmdGo
'
Me.cmdGo.Location = New System.Drawing.Point(8, 8)
Me.cmdGo.Name = "cmdGo"
Me.cmdGo.Size = New System.Drawing.Size(116, 23)
Me.cmdGo.TabIndex = 0
Me.cmdGo.Text = "Los geht's"
'
'pnlIcons
'
Me.pnlIcons.AutoScroll = True
Me.pnlIcons.Location = New System.Drawing.Point(4, 48)
Me.pnlIcons.Name = "pnlIcons"
Me.pnlIcons.Size = New System.Drawing.Size(664, 416)
Me.pnlIcons.TabIndex = 1
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(684, 481)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.pnlIcons, _
Me.cmdGo})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub cmdGo_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles cmdGo.Click
Dim path$ = Environment.GetFolderPath( _
Environment.SpecialFolder.Personal)
Dim di As New IO.DirectoryInfo(path)
Dim fi As IO.FileInfo
Dim ret%
Dim cnt%
Dim lastLoc As Point = New Point(0, 0)
Dim maxBottom% = 0
pnlIcons.Controls.Clear()
Me.toolTip.RemoveAll()
For Each fi In di.GetFiles
Dim shFi As New Api.SHFILEINFO()
ret = Api.SHGetFileInfo(fi.FullName, _
0, _
shFi, _
Marshal.SizeOf(shFi), _
Api.SHGFI.ICON Or Api.SHGFI.DISPLAYNAME)
If shFi.hIcon.Equals(IntPtr.Zero) Then
Debug.WriteLine(fi.FullName & " Iconhandle konnte nicht" & _
"ermittelt werden")
Else
Debug.WriteLine(fi.FullName & " Iconhandle: " & _
shFi.hIcon.ToInt32)
cnt += 1
AddIconPicBox(shFi, cnt, lastLoc, maxBottom)
Dim blnRet = Api.DestroyIcon(shFi.hIcon)
Debug.WriteLine("Icon-Handle zerstört: " & blnRet)
End If
Next
End Sub
Private Sub AddIconPicBox(ByVal shFi As Api.SHFILEINFO, ByVal cnt%, ByRef _
lastLoc As Point, ByRef maxBottom%)
Dim pBox As PictureBox
pBox = New PictureBox()
pBox.SizeMode = PictureBoxSizeMode.AutoSize
pBox.Image = Bitmap.FromHicon(shFi.hIcon)
pBox.Location = lastLoc
pnlIcons.Controls.Add(pBox)
If pBox.Bottom > maxBottom Then
maxBottom = pBox.Bottom
End If
Me.toolTip.SetToolTip(pBox, shFi.szDisplayName)
lastLoc.Offset(pBox.Width + 5, 0)
cnt += 1
If cnt Mod 10 = 0 Then
lastLoc = New Point(0, maxBottom + 5)
End If
End Sub
End ClassIch hoffe es funzt auch bei Dir.
Ciao
L.Y. |