Imports Leadtools.WinForms
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Drawing
Public Sub RasterImageList_Sorter(ByVal imageList As RasterImageList)
imageList.Bounds = New Rectangle(New Point(10, 10), New Size(400, 400))
' Sort the items in the list in ascending order.
imageList.Sorting = SortOrder.Ascending
' Use normal view style
imageList.ViewStyle = RasterImageListViewStyle.Normal
' Suspend painting the RasterImageList
imageList.BeginUpdate()
' Clear the image list
imageList.Items.Clear()
' Add 20 items
For i As Integer = 0 To 19
' Use the item index as its text
Dim item As RasterImageListItem = New RasterImageListItem(Nothing, i, i.ToString())
imageList.Items.Add(item)
Next i
' Resume painting
imageList.EndUpdate()
' Sort using the default sorter
imageList.Sort()
MessageBox.Show("Default sort (0, 1, 10, 11, etc...)")
' Setup custom sorting
imageList.Sorter = New MyRasterImageListItemComparer()
MessageBox.Show("Custom sort (0, 1, 2, 3, etc... ")
End Sub
<DllImport("SHLWAPI.DLL", EntryPoint:="StrCmpLogicalW", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function StrCmpLogicalW(ByVal psz1 As String, ByVal psz2 As String) As Integer
End Function
Private Class MyRasterImageListItemComparer : Implements IComparer
Public Sub New()
End Sub
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
Dim itemX As RasterImageListItem = CType(IIf(TypeOf x Is RasterImageListItem, x, Nothing), RasterImageListItem)
Dim itemY As RasterImageListItem = CType(IIf(TypeOf y Is RasterImageListItem, y, Nothing), RasterImageListItem)
Return StrCmpLogicalW(itemX.Text, itemY.Text)
End Function
End Class
using Leadtools.WinForms;
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Drawing;
public void RasterImageList_Sorter(RasterImageList imageList)
{
imageList.Bounds = new Rectangle(new Point(10, 10), new Size(400, 400));
// Sort the items in the list in ascending order.
imageList.Sorting = SortOrder.Ascending;
// Use normal view style
imageList.ViewStyle = RasterImageListViewStyle.Normal;
// Suspend painting the RasterImageList
imageList.BeginUpdate();
// Clear the image list
imageList.Items.Clear();
// Add 20 items
for(int i = 0; i < 20; i++)
{
// Use the item index as its text
RasterImageListItem item = new RasterImageListItem(null, i, i.ToString());
imageList.Items.Add(item);
}
// Resume painting
imageList.EndUpdate();
// Sort using the default sorter
imageList.Sort();
MessageBox.Show("Default sort (0, 1, 10, 11, etc...)");
// Setup custom sorting
imageList.Sorter = new MyRasterImageListItemComparer();
MessageBox.Show("Custom sort (0, 1, 2, 3, etc... ");
}
[DllImport("SHLWAPI.DLL", EntryPoint = "StrCmpLogicalW", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern int StrCmpLogicalW(string psz1, string psz2);
class MyRasterImageListItemComparer : IComparer
{
public MyRasterImageListItemComparer()
{
}
public int Compare(object x, object y)
{
RasterImageListItem itemX = x as RasterImageListItem;
RasterImageListItem itemY = y as RasterImageListItem;
return StrCmpLogicalW(itemX.Text, itemY.Text);
}
}