如何在form_load上将图像添加到glistview.谢谢! [英] how to add a image to the glistview on form_load. thanks!

查看:45
本文介绍了如何在form_load上将图像添加到glistview.谢谢!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在form_load上向glistview添加图像.谢谢!

私有子目录frmMain_Load(ByVal发送者为System.Object,ByVal e为System.EventArgs)处理MyBase.Load

SetIcons()
pLoad_ListView()
结束子

私人子pLoad_ListView()
Dim SQL As String
Dim n As Integer = 0
用途:此过程将填充提供的DataGrid
"以及系统中的所有有效数据.
SQL =选择tblMenu_Items.ItemText作为项,tblMenu_Items.ItemDesc作为描述,tblMenu_Items.form作为Form1,tblMenu_Items.form2,tblMenu_Items.pandemic_cde作为代码从tblMenu_Items那里tblMenu_Items.MenuID = 1和tblMenu_Items.InActive = False
Dim dr As OleDbDataReader
dr = myUsers.fdr(SQL)
n =博士FieldCount
GListView1.Items.Clear()
对于i As Integer = 0到n-1
GListView1.Columns.Add(dr.GetName(i).ToString(),60)
下一个
做While Dr.Read = True
昏暗的李作为新的ListViewItem
LI.Text = String.Concat9'''',dr(0),'''')
LI.SubItems.Add(String.Concat'''',dr(1),''''))
LI.SubItems.Add(String.Concat'''',dr(2),''''))
LI.SubItems.Add(String.Concat('''',dr(3),''''))
LI.SubItems.Add(String.Concat('''',dr(4),''''))
GListView1.Items.Add(LI)
循环

结束子
专用子SetIcons()
''将表单图标设置为Shell帮助图标
Dim hico As IntPtr()
ReDim hico(0)
ExtractSmallIconEx(&"shell32.dll&",23,IntPtr.Zero,hico,1)
Me.Icon = Icon.FromHandle(hico(0))
DestroyIcon(hico(0))
''使用Shell中的图标填充我们的ImageList.
ShellIcon(19,9)
结束子
专用子ShellIcon(ByVal StartIndex为整数,ByVal qty为整数)
''为了与Windows XP兼容,我们必须使用映像列表
''设置为16位颜色以存储图标.这是因为
''在从Icon/hIcon转换为位图的过程中
''图像的Alpha数据丢失并且那些阴影
''没有Alpha的表情看起来很丑.
Dim hico()As IntPtr = {New IntPtr}
ReDim hico(数量)
调用ExtractSmallIconEx(&"shell32.dll&",StartIndex,IntPtr.Zero,hico,qty)
Dim i As Integer
对于i = 0到数量-1
ImageList1.Images.Add(Icon.FromHandle(hico(i)))
下一个
结束子

地区外壳图标API& quot;
< DllImport(" shell32.dll& quot ;, EntryPoint:=& quot; ExtractIconEx& quot; CallingConvention:= CallingConvention.Cdecl)& _
私有共享函数ExtractSmallIconEx _
(ByVal lpszFile As String,_
ByVal nIconIndex为整数,_
ByVal phiconLarge As IntPtr,_
ByVal phiconSmall As IntPtr(),_
ByVal nIcons作为整数)作为布尔值
最终功能
< DllImport(& quot; user32& quot ;, CallingConvention:= CallingConvention.Cdecl)> _
私有共享函数DestroyIcon _
(ByVal hIcon作为IntPtr)作为布尔值
最终功能
#End Region


再次感谢

I was wondering how I can add a image to the glistview on form_load. thanks!

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

SetIcons()
pLoad_ListView()
End Sub

Private Sub pLoad_ListView()
Dim SQL As String
Dim n As Integer = 0
''PURPOSE: This procedure will fill the provided DataGrid
''with all the valid data in the system.
SQL = SELECT tblMenu_Items.ItemText as Item, tblMenu_Items.ItemDesc as Description, tblMenu_Items.form as Form1, tblMenu_Items.form2, tblMenu_Items.pandemic_cde as Code FROM tblMenu_Items WHERE tblMenu_Items.MenuID=1 AND tblMenu_Items.InActive=False;

Dim dr As OleDbDataReader
dr = myUsers.fdr(SQL)
n = dr.FieldCount
GListView1.Items.Clear()
For i As Integer = 0 To n - 1
GListView1.Columns.Add(dr.GetName(i).ToString(), 60)
Next
Do While dr.Read = True
Dim LI As New ListViewItem
LI.Text = String.Concat9'''', dr(0), '''')
LI.SubItems.Add(String.Concat'''', dr(1),''''))
LI.SubItems.Add(String.Concat'''', dr(2),''''))
LI.SubItems.Add(String.Concat('''',dr(3),''''))
LI.SubItems.Add(String.Concat('''',dr(4),''''))
GListView1.Items.Add(LI)
Loop

End Sub
Private Sub SetIcons()
''Set the Forms Icon to the Shell Help Icon
Dim hico As IntPtr()
ReDim hico(0)
ExtractSmallIconEx(&amp;quot;shell32.dll&amp;quot;, 23, IntPtr.Zero, hico, 1)
Me.Icon = Icon.FromHandle(hico(0))
DestroyIcon(hico(0))
''Fill our ImageList with Icons from the Shell.
ShellIcon(19, 9)
End Sub
Private Sub ShellIcon(ByVal StartIndex As Integer, ByVal qty As Integer)
''For Windows XP compatibility, we have to use an Imagelist
''set at 16 bit color to store the icon. This is because
''in the process of conversion from Icon/hIcon to bitmap
''the Alpha data for the image is lost and those shadows
''look ugly without Alpha.
Dim hico() As IntPtr = {New IntPtr}
ReDim hico(qty)
Call ExtractSmallIconEx(&amp;quot;shell32.dll&amp;quot;, StartIndex, IntPtr.Zero, hico, qty)
Dim i As Integer
For i = 0 To qty - 1
ImageList1.Images.Add(Icon.FromHandle(hico(i)))
Next
End Sub

Region &quot; Shell Icon API &quot;
&lt;DllImport(&quot;shell32.dll&quot;, EntryPoint:=&quot;ExtractIconEx&quot;, CallingConvention:=CallingConvention.Cdecl)&gt; _
Private Shared Function ExtractSmallIconEx _
(ByVal lpszFile As String, _
ByVal nIconIndex As Integer, _
ByVal phiconLarge As IntPtr, _
ByVal phiconSmall As IntPtr(), _
ByVal nIcons As Integer) As Boolean
End Function
&lt;DllImport(&quot;user32&quot;, CallingConvention:=CallingConvention.Cdecl)&gt; _
Private Shared Function DestroyIcon _
(ByVal hIcon As IntPtr) As Boolean
End Function
#End Region


thanks again

推荐答案

首先,学习如何使用pre标记来设置代码格式...或者甚至只是输入表单上的代码块"按钮您的答案.

其次,由于gListView继承了ListView,因此它与ListView相同.您已经设置了ImageList,这是第一步.然后,在gListView属性中,您必须将LargeImageList或SmallImageList设置为该ImageList. (您使用哪种视图取决于您的View是设置为LargeIcon还是SmallIcon.)但是,添加方式必须将ListViewItem的ImageList设置为ImageList然后,在添加新项时,添加与该项目关联的ImageKey.
First, learn how to use the pre tags to format your code...or even just the "code block" button on the form where you entered your answer.

Secondly, since gListView inherits ListView, it''s the same as a ListView. You''ve already set up your ImageList which is the first step. Then, in the gListView properties, you have to set either LargeImageList or SmallImageList to that ImageList. (Which one you use depends on whether your View is set to LargeIcon or SmallIcon.) Though, the way you''re adding it, you have to set the ListViewItem''s ImageList to the ImageList Then, when you add the new item, add the ImageKey associated with that item.
Dim LI As New ListViewItem
LI.Text = String.Concat('', dr(0), '')
LI.SubItems.Add(String.Concat('', dr(1),''))
LI.SubItems.Add(String.Concat('', dr(2),''))
LI.SubItems.Add(String.Concat('',dr(3),''))
LI.SubItems.Add(String.Concat('',dr(4),''))
LI.ImageList = ImageList1
LI.ImageKey = 5 'or whatever number it is


这篇关于如何在form_load上将图像添加到glistview.谢谢!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆