If a version cannot be found that exactly matches the size, the closest match is used. If the original parameter is an Icon that has a single size, this method only creates a duplicate icon. Use the stretching capabilities of the DrawImage method to resize the icon.
The following code example demonstrates how to use the ToBitmap method. This example is designed to be used with Windows Forms. Create a form and paste the following code into it. Call the IconToBitmap method in the form's Paint event handler, passing e as PaintEventArgs.
PrivateSub IconToBitmap(ByVal e As PaintEventArgs)
' Construct an Icon. Dim icon1 AsNew Icon(SystemIcons.Exclamation, 40, 40)
' Call ToBitmap to convert it. Dim bmp As Bitmap = icon1.ToBitmap()
' Draw the bitmap.
e.Graphics.DrawImage(bmp, New Point(30, 30))