I now know how to gather the file type icons and I'm able to use them in a
listview. But a listbox does not have a .smallimagelist or .largeimagelist
member, so I don't know how to translate that so that I have the icon + the
string in a listbox. Is this possible, and if so, can you give me some idea
how to go about it.
Thanks for any help.
Bernie Yaeger 4 1763
"Bernie Yaeger" <be*****@cherwe llinc.com> schrieb: I now know how to gather the file type icons and I'm able to use them in a listview. But a listbox does not have a .smallimagelist or .largeimagelist member, so I don't know how to translate that so that I have the icon + the string in a listbox. Is this possible, and if so, can you give me some idea how to go about it.
I am just curious why a listview control is not sufficient...
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Hi,
Try something like this.
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim arIcons As New ArrayList
Dim clsIco As New clsGetIcon
Dim diRoot As New IO.DirectoryInf o("C:\")
For Each fiCur As IO.FileInfo In diRoot.GetFiles
Dim c As New FileHelper
c.FileName = fiCur.Name
c.FileIcon = clsIco.getIcon( fiCur.FullName)
arIcons.Add(c)
Next
ListBox1.DrawMo de = DrawMode.OwnerD rawFixed
ListBox1.DataSo urce = arIcons
ListBox1.Displa yMember = "FileName"
End Sub
Private Sub ListBox1_DrawIt em(ByVal sender As Object, ByVal e As
System.Windows. Forms.DrawItemE ventArgs) Handles ListBox1.DrawIt em
Dim g As Graphics = e.Graphics
Dim br As SolidBrush
Dim s As String
Dim c As FileHelper
Try
c = DirectCast(List Box1.Items.Item (e.Index), FileHelper)
s = c.FileName
Catch ex As Exception
Trace.WriteLine (ex.ToString)
End Try
g.FillRectangle (Brushes.White, e.Bounds)
If CBool(e.State And DrawItemState.S elected) Then
g.FillRectangle (Brushes.LightB lue, e.Bounds)
End If
br = New SolidBrush(Colo r.Black)
g.DrawIcon(c.Fi leIcon, e.Bounds.Left, e.Bounds.Top)
g.DrawString(s, ListBox1.Font, br, e.Bounds.Left + 25, e.Bounds.Top)
br.Dispose()
End Sub
Helper classes
Public Class FileHelper
Dim ico As Icon
Dim strFile As String
Public Property FileIcon() As Icon
Get
Return ico
End Get
Set(ByVal Value As Icon)
ico = Value
End Set
End Property
Public Property FileName() As String
Get
Return strFile
End Get
Set(ByVal Value As String)
strFile = Value
End Set
End Property
End Class
Imports System.Runtime. InteropServices
Public Class clsGetIcon
Public Structure SHFILEINFO
Dim hIcon As IntPtr
Dim iIcon As Integer
Dim dwAttributes As Integer
<VBFixedString( 260), System.Runtime. InteropServices .MarshalAs( _
System.Runtime. InteropServices .UnmanagedType. ByValTStr, _
SizeConst:=260) > Public szDisplayName As String
'String that contains the name of the file as it appears in the Microsoft®
Windows® Shell, or the path and file name of the file that contains the icon
representing the file.
<VBFixedString( 80), System.Runtime. InteropServices .MarshalAs( _
System.Runtime. InteropServices .UnmanagedType. ByValTStr, _
SizeConst:=80)> Public szTypeName As String
End Structure
Private Declare Auto Function SHGetFileInfo Lib "shell32" (ByVal pszPath As
String, _
ByVal dwFileAttribute s As Integer, ByRef psfi As SHFILEINFO, _
ByVal cbFileInfo As Integer, ByVal uFlags As Integer) As Integer
Private Const SHGFI_ICON As Integer = &H100
Private Const SHGFI_SMALLICON As Integer = &H1 'Small icon
Private Const SHGFI_TYPENAME As Integer = &H400 ' get type name
Public Function getIcon(ByVal szFilename As String) As Icon
Try
Dim aSHFileInfo As New SHFILEINFO
Dim cbFileInfo As Integer = Marshal.SizeOf( aSHFileInfo)
Dim uflags As Integer = SHGFI_ICON Or SHGFI_SMALLICON
SHGetFileInfo(s zFilename, 0, aSHFileInfo, cbFileInfo, uflags)
Dim myIcon As Icon
myIcon = Icon.FromHandle (aSHFileInfo.hI con)
aSHFileInfo.szT ypeName = Space(255)
SHGetFileInfo(s zFilename, 0, aSHFileInfo, cbFileInfo, SHGFI_TYPENAME)
Trace.WriteLine (aSHFileInfo.sz TypeName)
Return myIcon
Catch ex As Exception
Debug.WriteLine (ex.ToString)
Return Nothing
End Try
End Function
End Class
Ken
---------------------
"Bernie Yaeger" <be*****@cherwe llinc.com> wrote in message
news:Of******** ******@TK2MSFTN GP15.phx.gbl...
I now know how to gather the file type icons and I'm able to use them in a
listview. But a listbox does not have a .smallimagelist or .largeimagelist
member, so I don't know how to translate that so that I have the icon + the
string in a listbox. Is this possible, and if so, can you give me some idea
how to go about it.
Thanks for any help.
Bernie Yaeger
Hi Herfried, Cor;
There are several reasons why the listview is inadequate.
I am trying to replicate the funtionality and display of the Outlook Express
attachment box. The listview does not give me a horizontal scrollbar until
there is a second column displayed, but the path string sometimes runs
beyond the bounds of the listview. In addition, I can't get a vertical
scrollbar in it. Third, I do not want multi cols. Fourth, only 'list' view
can do what I need done - even smallicon view is inadequate.
The listbox has most of what I need intrinsically.
Thanks to both of you for your responses, as always.
Bernie Yaeger
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:Os******** ******@TK2MSFTN GP10.phx.gbl... "Bernie Yaeger" <be*****@cherwe llinc.com> schrieb:I now know how to gather the file type icons and I'm able to use them in a listview. But a listbox does not have a .smallimagelist or .largeimageli st member, so I don't know how to translate that so that I have the icon + the string in a listbox. Is this possible, and if so, can you give me some idea how to go about it.
I am just curious why a listview control is not sufficient...
-- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Hi Ken,
Thanks, as always; I will try your suggestion.
Bernie
"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote in message
news:OX******** ********@tk2msf tngp13.phx.gbl. .. Hi,
Try something like this.
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
Dim arIcons As New ArrayList
Dim clsIco As New clsGetIcon
Dim diRoot As New IO.DirectoryInf o("C:\")
For Each fiCur As IO.FileInfo In diRoot.GetFiles
Dim c As New FileHelper
c.FileName = fiCur.Name
c.FileIcon = clsIco.getIcon( fiCur.FullName)
arIcons.Add(c)
Next
ListBox1.DrawMo de = DrawMode.OwnerD rawFixed
ListBox1.DataSo urce = arIcons
ListBox1.Displa yMember = "FileName"
End Sub
Private Sub ListBox1_DrawIt em(ByVal sender As Object, ByVal e As System.Windows. Forms.DrawItemE ventArgs) Handles ListBox1.DrawIt em
Dim g As Graphics = e.Graphics
Dim br As SolidBrush
Dim s As String
Dim c As FileHelper
Try
c = DirectCast(List Box1.Items.Item (e.Index), FileHelper)
s = c.FileName
Catch ex As Exception
Trace.WriteLine (ex.ToString)
End Try
g.FillRectangle (Brushes.White, e.Bounds)
If CBool(e.State And DrawItemState.S elected) Then
g.FillRectangle (Brushes.LightB lue, e.Bounds)
End If
br = New SolidBrush(Colo r.Black)
g.DrawIcon(c.Fi leIcon, e.Bounds.Left, e.Bounds.Top)
g.DrawString(s, ListBox1.Font, br, e.Bounds.Left + 25, e.Bounds.Top)
br.Dispose() End Sub Helper classes
Public Class FileHelper
Dim ico As Icon
Dim strFile As String
Public Property FileIcon() As Icon
Get
Return ico
End Get
Set(ByVal Value As Icon)
ico = Value
End Set
End Property
Public Property FileName() As String
Get
Return strFile
End Get
Set(ByVal Value As String)
strFile = Value
End Set
End Property
End Class Imports System.Runtime. InteropServices
Public Class clsGetIcon
Public Structure SHFILEINFO
Dim hIcon As IntPtr
Dim iIcon As Integer
Dim dwAttributes As Integer
<VBFixedString( 260), System.Runtime. InteropServices .MarshalAs( _
System.Runtime. InteropServices .UnmanagedType. ByValTStr, _
SizeConst:=260) > Public szDisplayName As String
'String that contains the name of the file as it appears in the Microsoft® Windows® Shell, or the path and file name of the file that contains the icon representing the file.
<VBFixedString( 80), System.Runtime. InteropServices .MarshalAs( _
System.Runtime. InteropServices .UnmanagedType. ByValTStr, _
SizeConst:=80)> Public szTypeName As String
End Structure Private Declare Auto Function SHGetFileInfo Lib "shell32" (ByVal pszPath As String, _
ByVal dwFileAttribute s As Integer, ByRef psfi As SHFILEINFO, _
ByVal cbFileInfo As Integer, ByVal uFlags As Integer) As Integer
Private Const SHGFI_ICON As Integer = &H100
Private Const SHGFI_SMALLICON As Integer = &H1 'Small icon
Private Const SHGFI_TYPENAME As Integer = &H400 ' get type name
Public Function getIcon(ByVal szFilename As String) As Icon
Try
Dim aSHFileInfo As New SHFILEINFO
Dim cbFileInfo As Integer = Marshal.SizeOf( aSHFileInfo)
Dim uflags As Integer = SHGFI_ICON Or SHGFI_SMALLICON
SHGetFileInfo(s zFilename, 0, aSHFileInfo, cbFileInfo, uflags)
Dim myIcon As Icon
myIcon = Icon.FromHandle (aSHFileInfo.hI con)
aSHFileInfo.szT ypeName = Space(255)
SHGetFileInfo(s zFilename, 0, aSHFileInfo, cbFileInfo, SHGFI_TYPENAME)
Trace.WriteLine (aSHFileInfo.sz TypeName)
Return myIcon
Catch ex As Exception
Debug.WriteLine (ex.ToString)
Return Nothing
End Try
End Function
End Class Ken
---------------------
"Bernie Yaeger" <be*****@cherwe llinc.com> wrote in message news:Of******** ******@TK2MSFTN GP15.phx.gbl... I now know how to gather the file type icons and I'm able to use them in a listview. But a listbox does not have a .smallimagelist or .largeimagelist member, so I don't know how to translate that so that I have the icon + the string in a listbox. Is this possible, and if so, can you give me some idea how to go about it.
Thanks for any help.
Bernie Yaeger This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Eric |
last post by:
I implemented owner drawing on the main and context menus of my main form.
It works fine.
There is also a notify icon control that has a context menu. When the icon
is in the status bar, it works perfectly fine when it is double-clicked.
However, when I try to initialize the notify icon's context menu as an
owner-drawn menu, all the text in that menu disappears.
Is owner drawing a notify icon's context menu possible? I saw someone...
|
by: Patty O'Dors |
last post by:
Hi
I have some code to create an ownerdrawn listbox (derived), and when I add
an item to it, the bold text of the first item (the title, 'Collections and
Maturities') mysteriously seems to get bunched up at the right, i.e. squashed
up! any idea why?
The main bit of the code is as such
// (in progressReporter.cs)
protected struct LBRow //a row of the listbox, whether it be the title or a
|
by: Bernie Yaeger |
last post by:
I now know how to gather the file type icons and I'm able to use them in a
listview. But a listbox does not have a .smallimagelist or .largeimagelist
member, so I don't know how to translate that so that I have the icon + the
string in a listbox. Is this possible, and if so, can you give me some idea
how to go about it.
Thanks for any help.
Bernie Yaeger
|
by: LostInMd |
last post by:
Hi All,
I've got an owner drawn listBox where I draw and measure the items that I add
to the listBox. For example, I have a listBox that can only display 10
characters on each horizontal line. The majority of my items contain much
more than 10 characters and thus the reason for my use of owner drawn
listBoxes - I do not want to use a horizontal scrollbar, instead I want the
text of each item to wrap onto multiple lines. I do use a...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |