TextBox.GetCharacterIndexFromPoint Method

Returns the zero-based insertion index for a specified point.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)

public int GetCharacterIndexFromPoint (
	Point point,
	bool snapToText
public int GetCharacterIndexFromPoint (
	Point point, 
	boolean snapToText
public function GetCharacterIndexFromPoint (
	point : Point, 
	snapToText : boolean
) : int
You cannot use methods in XAML.



A point in TextBox coordinate-space for which to return an insertion index.


true to return the nearest insertion index if there is no character at the specified point; false to return -1 if there is no character at the specified point.

Return Value

The insertion index for the specified point, or -1 if no valid insertion index can be found.

An insertion index references a position between characters; contrast with a character index, which references specific characters. Text that is N characters long will have N+1 possible insertion indices. An insertion index of M could mean the given point was in the right half of the character to the left of M, or on the left half of the point to the right of M.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0