HitTest Method

Summary

Queries the specified location to determine if the point is over a RasterImageListItem.

Syntax

C#
C++/CLI
C++
public RasterImageListItem HitTest( 
   int x, 
   int y 
) 
public: 
RasterImageListItem^ HitTest(  
   int x, 
   int y 
)  
public:  
   RasterImageListItem^ HitTest( 
      Int32 x, 
      Int32 y 
   ) 

Parameters

x
The horizontal position of the coordinate in client coordinates.

y
The vertical position of the coordinate in client coordinates.

Return Value

An RasterImageListItem object under the given location, or null (Nothing in VB) if no RasterImageListItem is under the location.

Example

This example will create and populate a RasterImageList control, and then performs hittesting when the user right clicks on the control and shows the item information.

C#
using Leadtools.WinForms; 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
 
class MyForm4 : Form 
{ 
   RasterImageList imageList; 
   RasterCodecs codecs; 
 
   public MyForm4(string title) 
   { 
      Text = title; 
 
      // Set the size of the form 
      Size = new Size(400, 200); 
 
      // Create a new RasterImageList control 
      imageList = new RasterImageList(); 
      imageList.Dock = DockStyle.Fill; 
      imageList.SelectionMode = RasterImageListSelectionMode.Single; 
      imageList.Size = Size; 
      Controls.Add(imageList); 
      imageList.BringToFront(); 
 
      codecs = new RasterCodecs(); 
 
      // 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() + ".cmp"); 
         RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1); 
         RasterImageListItem item = new RasterImageListItem(image, 1, "Item" + index.ToString()); 
 
         // Select the first item 
         if (i == 0) 
            item.Selected = true; 
 
         // Add the item to the image list 
         imageList.Items.Add(item); 
      } 
 
 
      // Add a handler to the MouseDown event 
      imageList.MouseDown += new MouseEventHandler(rasterImageList_MouseDown); 
 
      // Add the RasterImageList to the control collection. 
      Controls.Add(imageList); 
   } 
 
   private void rasterImageList_MouseDown(object sender, MouseEventArgs e) 
   { 
      // Check for right button clicks 
      if (e.Button == MouseButtons.Right) 
      { 
         // Check if any item is under the cursor poisition 
         RasterImageList imageList = sender as RasterImageList; 
         RasterImageListItem item = imageList.HitTest(e.X, e.Y); 
         if (item != null) 
         { 
            // Yes, show the item text in a message box 
            MessageBox.Show(this, item.Text); 
         } 
      } 
   } 
} 
 
public void RasterImageList_HitTest(string title) 
{ 
   MyForm4 form = new MyForm4(title); 
   form.ShowDialog(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 

Requirements

Target Platforms

See Also

Reference

RasterImageList Class

RasterImageList Members

Help Version 22.0.2023.2.9
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.WinForms Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.