Leadtools.Windows.Controls Namespace > ImageList Class : HitTest(Point) Method |
'Usage Dim instance As ImageList Dim point As Point Dim value As Integer value = instance.HitTest(point)
function Leadtools.Windows.Controls.ImageList.HitTest(Point)( point )
Private Class MyWindow3 : Inherits Window Private imageList As ImageList Public Sub New(ByVal title As String) title = title ' Set the size of the form Width = 400 Height = 200 ' Create a new ImageList control imageList = New ImageList() imageList.Background = Brushes.Red imageList.SelectionMode = SelectionMode.Single imageList.Width = Width imageList.Height = Height Content = imageList ' Create three items Dim imagesPath As String = LEAD_VARS.ImagesDir For i As Integer = 0 To 2 ' Load the image Dim index As Integer = i + 1 Dim imageFileName As String = Path.Combine(imagesPath, "ImageProcessingDemo\Image" & index.ToString() & ".jpg") Dim item As ImageListItem = New ImageListItem() item.Source = New BitmapImage(New Uri(imageFileName)) item.Text = "item" & index.ToString() ' Select the first item If i = 0 Then item.IsSelected = True End If ' Add the item to the image list imageList.Items.Add(item) Next i ' Add a handler to the MouseDown event AddHandler imageList.PreviewMouseDown, AddressOf ImageList_MouseDown End Sub Private Sub ImageList_MouseDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs) ' Check for right button clicks If e.RightButton = MouseButtonState.Pressed Then ' Check if any item is under the cursor poisition Dim imageList As ImageList = TryCast(sender, ImageList) Dim item As ImageListItem = TryCast(imageList.Items(imageList.HitTest(e.GetPosition(imageList))), ImageListItem) If Not item Is Nothing Then ' Yes, show the item text in a message box MessageBox.Show(Me, item.Text) End If End If End Sub End Class Public Sub ImageList_HitTest(ByVal title As String) Dim window As MyWindow3 = New MyWindow3(title) window.ShowDialog() End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
class MyWindow3 : Window { ImageList imageList; public MyWindow3(string title) { Title = title; // Set the size of the form Width = 400; Height = 200; // Create a new ImageList control imageList = new ImageList(); imageList.Background = Brushes.Red; imageList.SelectionMode = SelectionMode.Single; imageList.Width = Width; imageList.Height = Height; Content = imageList; // Create three items string imagesPath = LEAD_VARS.ImagesDir; for (int i = 0; i < 3; i++) { // Load the image int index = i + 1; string imageFileName = Path.Combine(imagesPath, @"ImageProcessingDemo\Image" + index.ToString() + ".jpg"); ImageListItem item = new ImageListItem(); item.Source = new BitmapImage(new Uri(imageFileName)); item.Text = "item" + index.ToString(); // Select the first item if (i == 0) item.IsSelected = true; // Add the item to the image list imageList.Items.Add(item); } // Add a handler to the MouseDown event AddHandler(ImageListItem.MouseDownEvent, new MouseButtonEventHandler(ImageList_MouseDown)); imageList.PreviewMouseDown += new MouseButtonEventHandler(ImageList_MouseDown); } private void ImageList_MouseDown(object sender, MouseButtonEventArgs e) { // Check for right button clicks if (e.RightButton == MouseButtonState.Pressed) { // Check if any item is under the cursor poisition ImageList imageList = sender as ImageList; ImageListItem item = imageList.Items[imageList.HitTest(e.GetPosition(imageList))] as ImageListItem; if (item != null) { // Yes, show the item text in a message box MessageBox.Show(this, item.Text); } } } } public void ImageList_HitTest(string title) { MyWindow3 window = new MyWindow3(title); window.ShowDialog(); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
class MyWindow3 : ChildWindow { ImageList imageList; public MyWindow3(string title) { Title = title; // Set the size of the form Width = 400; Height = 200; // Create a new ImageList control imageList = new ImageList(); imageList.Background = new SolidColorBrush(Colors.Red); imageList.SelectionMode = SelectionMode.Single; imageList.Width = Width; imageList.Height = Height; Content = imageList; // Create three items string imagesPath = LeadtoolsExamples.Common.ImagesPath.Path; for (int i = 0; i < 3; i++) { // Load the image int index = i + 1; string imageFileName = imagesPath + "Image" + index.ToString() + ".jpg"; ImageListItem item = new ImageListItem(); item.Source = new BitmapImage(new Uri(imageFileName)); item.Text = "item" + index.ToString(); // Select the first item if (i == 0) item.IsSelected = true; // Add the item to the image list imageList.Items.Add(item); } // Add a handler to the MouseDown event AddHandler(ImageListItem.MouseLeftButtonDownEvent, new MouseButtonEventHandler(imageList_MouseLeftButtonDown), false); imageList.MouseLeftButtonDown +=new MouseButtonEventHandler(imageList_MouseLeftButtonDown); } void imageList_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { // Check if any item is under the cursor position ImageList imageList = sender as ImageList; ImageListItem item = imageList.Items[imageList.HitTest(e.GetPosition(imageList))] as ImageListItem; if (item != null) { // Yes, show the item text in a message box MessageBox.Show(item.Text); } } } public void ImageList_HitTest(string title) { MyWindow3 window = new MyWindow3(title); window.Show(); }
Private Class MyWindow3 : Inherits ChildWindow Private imageList As ImageList Public Sub New(ByVal title As String) title = title ' Set the size of the form Width = 400 Height = 200 ' Create a new ImageList control imageList = New ImageList() imageList.Background = New SolidColorBrush(Colors.Red) imageList.SelectionMode = SelectionMode.Single imageList.Width = Width imageList.Height = Height Content = imageList ' Create three items Dim imagesPath As String = LeadtoolsExamples.Common.ImagesPath.Path For i As Integer = 0 To 2 ' Load the image Dim index As Integer = i + 1 Dim imageFileName As String = imagesPath & "Image" & index.ToString() & ".jpg" Dim item As ImageListItem = New ImageListItem() item.Source = New BitmapImage(New Uri(imageFileName)) item.Text = "item" & index.ToString() ' Select the first item If i = 0 Then item.IsSelected = True End If ' Add the item to the image list imageList.Items.Add(item) Next i ' Add a handler to the MouseDown event AddHandler imageList.MouseLeftButtonDown, AddressOf imageList_MouseLeftButtonDown End Sub Private Sub imageList_MouseLeftButtonDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs) ' Check if any item is under the cursor position Dim imageList As ImageList = TryCast(sender, ImageList) Dim item As ImageListItem = TryCast(imageList.Items(imageList.HitTest(e.GetPosition(imageList))), ImageListItem) If Not item Is Nothing Then ' Yes, show the item text in a message box MessageBox.Show(item.Text) End If End Sub End Class Public Sub ImageList_HitTest(ByVal title As String) Dim window As MyWindow3 = New MyWindow3(title) window.Show() End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2