Retrieves the item from the cursor.
Type | Description | |||
X as OLE_XPOS_PIXELS | A single that specifies the current X location of the mouse pointer. The x values is always expressed in client coordinates. | |||
Y as OLE_YPOS_PIXELS | A single that specifies the current Y location of the mouse pointer. The y values is always expressed in client coordinates. | |||
ColIndex as Long | A long expression that indicates on return, the column where the point belongs. If the return value is zero, the ColIndex may indicate the handle of the cell ( inner cell ). | |||
HitTestInfo as HitTestInfoEnum | A HitTestInfoEnum expression that determines on return, the position of the cursor within the cell. | |||
HITEM | A long expression that indicates the item's handle where the point is. |
Use the ItemFromPoint property to get the item from the point specified by the {X,Y}. The X and Y coordinates are expressed in client coordinates, so a conversion must be done in case your coordinates are relative to the screen or to other window.
The ItemFromPoint property returns:
Use the ColumnFromPoint property to retrieve the column from cursor. Use the DateFromPoint property to specify the date from the cursor. Use the SelectableItem property to specify the user can select an item. Use the BarFromPoint property to get the bar from the point. Use the LinkFromPoint property to get the link from the point.
The following VB sample prints the cell's caption from the cursor ( if the control contains no inner cells. Use the SplitCell property to insert inner cells ) :
Private Sub G2antt1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) On Error Resume Next ' Converts the container coordinates to client coordinates X = X / Screen.TwipsPerPixelX Y = Y / Screen.TwipsPerPixelY Dim h As HITEM Dim c As Long Dim hit As EXG2ANTTLibCtl.HitTestInfoEnum ' Gets the item from (X,Y) h = G2antt1.ItemFromPoint(X, Y, c, hit) If Not (h = 0) Then Debug.Print G2antt1.Items.CellValue(h, c) & " HT = " & hit End If End Sub
The following VB sample displays the cell's caption from the cursor ( if the control contains inner cells ):
Private Sub G2antt1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) On Error Resume Next ' Converts the container coordinates to client coordinates X = X / Screen.TwipsPerPixelX Y = Y / Screen.TwipsPerPixelY Dim h As HITEM Dim c As Long Dim hit As EXG2ANTTLibCtl.HitTestInfoEnum ' Gets the item from (X,Y) h = G2antt1.ItemFromPoint(X, Y, c, hit) If Not (h = 0) Or Not (c = 0) Then Debug.Print G2antt1.Items.CellValue(h, c) & " HT = " & hit End If End Sub
The following VB sample displays the index of icon being clicked:
Private Sub G2antt1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim i As HITEM, h As HitTestInfoEnum, c As Long With G2antt1 i = .ItemFromPoint(X / Screen.TwipsPerPixelX, Y / Screen.TwipsPerPixelY, c, h) End With If (i <> 0) or ( c <> 0 ) Then If exHTCellIcon = (h And exHTCellIcon) Then Debug.Print "The index of icon being clicked is: " & (h And &HFFFF0000) / 65536 End If End If End Sub
The following C# sample displays the caption of the cell being double clicked ( including the inner cells ):
EXG2ANTTLib.HitTestInfoEnum hit; int c = 0, h = axG2antt1.get_ItemFromPoint( e.x, e.y, out c, out hit ); if ( ( h != 0 ) || ( c != 0 ) ) MessageBox.Show( axG2antt1.Items.get_CellValue( h, c ).ToString() );
The following VC sample displays the caption of the cell being clicked:
#include "Items.h" static CString V2S( VARIANT* pv, LPCTSTR szDefault = _T("") ) { if ( pv ) { if ( pv->vt == VT_ERROR ) return szDefault; COleVariant vt; vt.ChangeType( VT_BSTR, pv ); return V_BSTR( &vt ); } return szDefault; } void OnMouseDownG2antt1(short Button, short Shift, long X, long Y) { long c = 0, hit = 0, hItem = m_g2antt.GetItemFromPoint( X, Y, &c, &hit ); if ( ( hItem != 0 ) || ( c != 0 ) ) { CItems items = m_g2antt.GetItems(); COleVariant vtItem( hItem ), vtColumn( c ); CString strCaption = V2S( &items.GetCellValue( vtItem, vtColumn ) ), strOutput; strOutput.Format( "Cell: '%s', Hit = %08X\n", strCaption, hit ); OutputDebugString( strOutput ); } }
The following VB.NET sample displays the caption from the cell being clicked:
Private Sub AxG2antt1_MouseDownEvent(ByVal sender As Object, ByVal e As AxEXG2ANTTLib._IG2anttEvents_MouseDownEvent) Handles AxG2antt1.MouseDownEvent With AxG2antt1 Dim i As Integer, c As Integer, hit As EXG2ANTTLib.HitTestInfoEnum i = .get_ItemFromPoint(e.x, e.y, c, hit) If (Not (i = 0) Or Not (c = 0)) Then Debug.WriteLine("Cell: " & .Items.CellValue(i, c) & " Hit: " & hit.ToString()) End If End With End Sub
The following C# sample displays the caption from the cell being clicked:
private void axG2antt1_MouseDownEvent(object sender, AxEXG2ANTTLib._IG2anttEvents_MouseDownEvent e) { int c = 0; EXG2ANTTLib.HitTestInfoEnum hit; int i = axG2antt1.get_ItemFromPoint( e.x, e.y, out c,out hit ); if ( ( i != 0 ) || ( c != 0 ) ) { string s = axG2antt1.Items.get_CellValue( i,c ).ToString(); s = "Cell: " + s + ", Hit: " + hit.ToString(); System.Diagnostics.Debug.WriteLine( s ); } }
The following VFP sample displays the caption from the cell being clicked ( the code should be in the G2antt1.MouseDown event ):
*** ActiveX Control Event *** LPARAMETERS button, shift, x, y local c, hit c = 0 hit = 0 with thisform.G2antt1 .Items.DefaultItem = .ItemFromPoint( x, y, @c, @hit ) if ( .Items.DefaultItem <> 0 ) or ( c <> 0 ) wait window nowait .Items.CellValue( 0, c ) + " " + Str( hit ) endif endwith