Hi all,

I have a rather interesting problem. I'm trying to create a Windows Explorer type application, and the first step I'm trying to accomplish is to get the icons drawn.

I got the icon boxes themselves working smoothly, but now I'm trying to draw the icons.

VisibleItems is the array of the items I want to draw on the screen.

FBIcon is a class I wrote that contains the icon's data (path, location, name, whether it is selected, ect). It doesn't inherit System.Windows.Forms.Control; it is a standalone class. I'm trying to stay away from controls if I can to maximize speed and efficiency.

As you can see from the code below, it uses Icon.ExtractAssociatedIcon() to get the appropriate icon based on the file type, and then it draws it to the correct location.

Code:
If VisibleItems IsNot Nothing Then
    For Each element As FBIcon In VisibleItems
        Dim tileImage As Bitmap
        Try
            tileImage = Icon.ExtractAssociatedIcon(element.Path).ToBitmap()
        Catch ex As Exception
            tileImage = Image.FromFile("") 'placeholder image
        End Try
        e.Graphics.DrawImage(tileImage, element.Location.X + ((getIconWidth() - tileImage.Width) \ 2), element.Location.Y + ((getIconHeight() - tileImage.Height) \ 2))
    Next
End If
It works good; the layout logic performs the way I want it to, and there are (for the most part) no bugs.

The problem I'm having is with its speed. This code can be run up to a few hundred times every time the form is resized. It's not severely laggy, but it does slow down the form noticeably (especially if the form is maximized and there are a lot of icons being drawn.

So basically, I'm looking for a way to optimize this code. Do you guys know of a way to draw images really quickly? Also, is there a way to get a file icon based on its type really quickly?

If not, is there a different way of approaching this that would achieve the same result?

- Simek