Leadtools.Windows.Controls Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.03.25
HitTest Method
See Also  Example
Leadtools.Windows.Controls Namespace > ImageList Class : HitTest Method




point
Represents the horizontal and vertical position of the coordinate in client coordinates.
Queries the specified location to determine whether the point is over an ImageListItem.

Syntax

Visual Basic (Declaration) 
Public Function HitTest( _
   ByVal point As Point _
) As Integer
Visual Basic (Usage)Copy Code
Dim instance As ImageList
Dim point As Point
Dim value As Integer
 
value = instance.HitTest(point)
C# 
public int HitTest( 
   Point point
)
Managed Extensions for C++ 
public: int HitTest( 
   Point point
) 
C++/CLI 
public:
int HitTest( 
   Point point
) 

Parameters

point
Represents the horizontal and vertical position of the coordinate in client coordinates.

Return Value

An ImageListItem object under the given location, or null (Nothing in Visual Basic) if no ImageListItem is under the location.

Example

This example will create and populate a ImageList control, and then perform hittesting when the user right-clicks on the control and views the item information.

Visual BasicCopy Code
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 = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\"

      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(New BitmapImage(New Uri(imageFileName)), "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 = CType(IIf(TypeOf sender Is ImageList, sender, Nothing), ImageList)
         Dim item As ImageListItem = CType(IIf(TypeOf imageList.Items(imageList.HitTest(e.GetPosition(imageList))) Is ImageListItem, imageList.Items(imageList.HitTest(e.GetPosition(imageList))), Nothing), 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
C#Copy Code
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 = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\"; 
 
      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(new BitmapImage(new Uri(imageFileName)), "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(); 
}

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Vista, and Windows Server 2003 family

See Also