Queries the specified location to determine if the point is over an
RasterImageListItem.
Syntax
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 Visual Basic) 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.
Visual Basic | Copy Code |
---|
Private Class MyForm4 : Inherits Form
Private imageList As RasterImageList
Private codecs As RasterCodecs
Public Sub New(ByVal title As String)
Text = title
Size = New Size(400, 200)
imageList = New RasterImageList()
imageList.Dock = DockStyle.Fill
imageList.SelectionMode = RasterImageListSelectionMode.Single
imageList.Size = Size
Controls.Add(imageList)
imageList.BringToFront()
RasterCodecs.Startup()
codecs = New RasterCodecs()
Dim imagesPath As String = "C:\program files\LEAD Technologies\LEADTOOLS 15\Images\"
For i As Integer = 0 To 2
Dim index As Integer = i + 1
Dim imageFileName As String = imagesPath & "Image" & index.ToString() & ".cmp"
Dim image As RasterImage = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
Dim item As RasterImageListItem = New RasterImageListItem(image, 1, "Item" & index.ToString())
If i = 0 Then
item.Selected = True
End If
imageList.Items.Add(item)
Next i
RasterCodecs.Shutdown()
AddHandler imageList.MouseDown, AddressOf rasterImageList_MouseDown
Controls.Add(imageList)
End Sub
Private Sub rasterImageList_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
If e.Button = Windows.Forms.MouseButtons.Right Then
Dim imageList As RasterImageList = CType(IIf(TypeOf sender Is RasterImageList, sender, Nothing), RasterImageList)
Dim item As RasterImageListItem = imageList.HitTest(e.X, e.Y)
If Not item Is Nothing Then
MessageBox.Show(Me, item.Text)
End If
End If
End Sub
End Class
Public Sub RasterImageList_HitTest(ByVal title As String)
Dim form As MyForm4 = New MyForm4(title)
form.ShowDialog()
End Sub |
C# | Copy Code |
---|
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(); RasterCodecs.Startup(); codecs = new RasterCodecs(); // 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() + ".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); } RasterCodecs.Shutdown(); // 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(); } |
Requirements
Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also