Put icon into Picturebox

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
***************************
 
S

SStory

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
 
A

Armin Zingler

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.
 
S

SStory

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)
 
Y

yxq

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
 
S

SStory

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top