Why is the image in picturebox ugly?

Y

yxq

Please add the manifest file!

*************************************************************
Imports System
Imports System.Drawing
Imports System.Runtime.InteropServices
Module Module1
Public Class MyClsIcon


'===========================================================================
==========
' Enumerations

'===========================================================================
==========
<Flags()> Private Enum SHGFI
SmallIcon = &H1
LargeIcon = &H0
Icon = &H100
DisplayName = &H200
Typename = &H400
SysIconIndex = &H4000
UseFileAttributes = &H10
End Enum

Public Enum IconSize
SmallIcon = 1
LargeIcon = 0
End Enum


'===========================================================================
==========
' Structures

'===========================================================================
==========
<StructLayout(LayoutKind.Sequential)> _
Private Structure SHFILEINFO
Public hIcon As IntPtr
Public iIcon As Integer
Public dwAttributes As Integer
<MarshalAs(UnmanagedType.LPStr, SizeConst:=260)> Public
szDisplayName As String
<MarshalAs(UnmanagedType.LPStr, SizeConst:=80)> Public
szTypeName As String

Public Sub New(ByVal B As Boolean)
hIcon = IntPtr.Zero
iIcon = 0
dwAttributes = 0
szDisplayName = vbNullString
szTypeName = vbNullString
End Sub
End Structure


'===========================================================================
==========
' API Calls

'===========================================================================
==========
Private Declare Auto Function SHGetFileInfo Lib "shell32" (ByVal
pszPath As String, ByVal dwFileAttributes As Integer, ByRef psfi As
SHFILEINFO, ByVal cbFileInfo As Integer, ByVal uFlagsn As SHGFI) As Integer


'===========================================================================
==========
' Functions and Procedures...

'===========================================================================
==========
Public Shared Function GetDefaultIcon(ByVal Path As String, Optional
ByVal IconSize As IconSize = IconSize.SmallIcon, Optional ByVal SaveIconPath
As String = "") As Icon
Dim info As New SHFILEINFO(True)
Dim cbSizeInfo As Integer = Marshal.SizeOf(info)
Dim flags As SHGFI = SHGFI.Icon Or SHGFI.UseFileAttributes
flags = flags + IconSize
SHGetFileInfo(Path, 256, info, cbSizeInfo, flags)
GetDefaultIcon = Icon.FromHandle(info.hIcon)
If SaveIconPath <> "" Then
Dim FileStream As New IO.FileStream(SaveIconPath,
IO.FileMode.Create)
GetDefaultIcon.Save(FileStream)
FileStream.Close()
End If
End Function 'GetDefaultIcon(ByVal Path As String, Optional ByVal
IconSize As IconSize = IconSize.SmallIcon, Optional ByVal SaveIconPath As
String = "") As Icon

'===========================================================================
==========
Public Shared Function ImageToIcon(ByVal SourceImage As Image) As
Icon
' converts an image into an icon
Dim TempBitmap As New Bitmap(SourceImage)
ImageToIcon = Icon.FromHandle(TempBitmap.GetHicon())
TempBitmap.Dispose()
End Function 'ImageToIcon(ByVal SourceImage As Image) As Icon

'===========================================================================
==========

End Class
Public Declare Unicode Function PickIconDlg _
Lib "shell32.dll" Alias "#62" ( _
ByVal hwndOwner As IntPtr, _
ByVal lpstrFile As System.Text.StringBuilder, _
ByVal nMaxFile As Integer, _
ByRef lpdwIconIndex As Integer) _
As Integer

Public Declare Function ExtractIcon _
Lib "shell32.dll" Alias "ExtractIconA" ( _
ByVal hInst As IntPtr, _
ByVal lpszExeFileName As String, _
ByVal nIconIndex As Integer) _
As IntPtr

Public Declare Function DestroyIcon _
Lib "user32.dll" (ByVal hIcon As Integer) _
As Integer
End Module
****************************************************************************
*****

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim ObjLVI As ListViewItem
Dim arrItem(1) As String
Dim eachDrv As String
Dim ObjSize As New Size()
ObjSize.Height = 32
ObjSize.Width = 32

ImageList1.ImageSize = ObjSize
ImageList1.ColorDepth = ColorDepth.Depth32Bit
ListView1.LargeImageList = ImageList1

For Each eachDrv In System.Environment.GetLogicalDrives
arrItem(0) = eachDrv
ObjLVI = New ListViewItem(arrItem)
ImageList1.Images.Add(MyClsIcon.GetDefaultIcon(arrItem(0),
MyClsIcon.IconSize.LargeIcon, ""))
ObjLVI.ImageIndex = ImageList1.Images.Count - 1

ListView1.Items.Add(ObjLVI)
Next
End Sub

Private Sub ListView1_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ListView1.SelectedIndexChanged
Try
PictureBox1.Image =
ImageList1.Images(ListView1.SelectedItems(0).ImageIndex)
Catch
End Try
End Sub
****************************************************************************
**********

Thanks
 
O

One Handed Man [ OHM ]

Because you used a photo of your granny without her teeth.

Sorry , couldnt resist that !!

LMAO
 
C

CJ Taylor

Ya know... Normally I would have said something like this was childish and
stupid.

but.........

ya did leave youself wide open for that one... and a lot worse.


Herfried K. Wagner said:
"One Handed Man [ OHM ]" <terry_burnsREMOVE%FOR%NO%[email protected]> scripsit:
Because you used a photo of your granny without her teeth.

Sorry , couldnt resist that !!

ROFLM*O
 

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

Top