Put icon into Picturebox

  • Thread starter Thread starter yxq
  • Start date Start date
Y

yxq

Thank Armin Zingler, the codes below work well!
But i want to put the icon into Picturebox1 instead of the Form1, how to do?

the code
**************************
If retval <> 0 Then
Dim g As Graphics
Dim ico As Icon
Dim hIcon As IntPtr ' handle to the icon once it is extracted
hIcon = ExtractIcon(VB6.GetHInstance, iconfile, iconindex)
ico = Icon.FromHandle(hIcon)
p.Image.FromHbitmap(hIcon)
g = Form1.DefInstance.CreateGraphics
g.DrawIcon(ico, 0, 0)
g.Dispose()
retval = DestroyIcon(hIcon.ToInt32)
End If
***************************
 
How about this....?

Dim ico As Icon
Dim p As New PictureBox
Dim hIcon As IntPtr ' handle to the icon once it is extracted
hIcon = ExtractIcon(VB6.GetHInstance, iconfile, iconindex)
ico = Icon.FromHandle(hIcon)
p.Image = i.ToBitmap
retval = DestroyIcon(hIcon.ToInt32)

Won't this work?

Just a thought... I think it should work. Is there no easier way for you to
get and icon than to resort to an API call?

Shane
 
yxq said:
Thank Armin Zingler, the codes below work well!
But i want to put the icon into Picturebox1 instead of the Form1, how
to do?

the code
**************************
If retval <> 0 Then
Dim g As Graphics
Dim ico As Icon
Dim hIcon As IntPtr ' handle to the icon once it is
extracted hIcon = ExtractIcon(VB6.GetHInstance, iconfile,
iconindex)
ico = Icon.FromHandle(hIcon)
p.Image.FromHbitmap(hIcon)
g = Form1.DefInstance.CreateGraphics
g.DrawIcon(ico, 0, 0)
g.Dispose()
retval = DestroyIcon(hIcon.ToInt32)
End If
***************************


Declare ico at class level and call DrawIcon in the Picturebox' Paint event.

Or: Derive your own class from Picturebox, add an Icon property and draw the
icon in OnPaint.
 
oops... i meant

Dim ico As Icon
Dim p As New PictureBox
Dim hIcon As IntPtr ' handle to the icon once it is extracted
hIcon = ExtractIcon(VB6.GetHInstance, iconfile, iconindex)
ico = Icon.FromHandle(hIcon)
p.Image = ico.ToBitmap
retval = DestroyIcon(hIcon.ToInt32)
 
Thank you very much!
It works well!


SStory said:
oops... i meant

Dim ico As Icon
Dim p As New PictureBox
Dim hIcon As IntPtr ' handle to the icon once it is extracted
hIcon = ExtractIcon(VB6.GetHInstance, iconfile, iconindex)
ico = Icon.FromHandle(hIcon)
p.Image = ico.ToBitmap
retval = DestroyIcon(hIcon.ToInt32)

you
 
Glad to help someone... Need plenty myself.
I am new to .NET and having to learn a lot, but was really good at the
predecessor.

Take care,

Shane
 
Back
Top