TextBoxBase.GetCharIndexFromPosition(Point) 方法

定義

擷取最接近指定位置之字元的索引。Retrieves the index of the character nearest to the specified location.

public:
 virtual int GetCharIndexFromPosition(System::Drawing::Point pt);
public virtual int GetCharIndexFromPosition (System.Drawing.Point pt);
abstract member GetCharIndexFromPosition : System.Drawing.Point -> int
override this.GetCharIndexFromPosition : System.Drawing.Point -> int
Public Overridable Function GetCharIndexFromPosition (pt As Point) As Integer

參數

pt
Point

要搜尋的位置。The location to search.

傳回

Int32

指定位置處的以零為起始的字元索引。The zero-based character index at the specified location.

備註

這個方法會傳回最接近參數中指定之位置的字元索引 ptThis method returns the character index that is closest to the position specified in the pt parameter. 字元索引是控制項中文字的以零為基底的索引,包括空格。The character index is a zero-based index of text in the control, including spaces. 您可以使用這個方法,藉由將滑鼠座標傳遞給這個方法,以判斷使用者在文字中的位置。You can use this method to determine where in the text the user has the mouse over by passing the mouse coordinates to this method. 如果您想要在使用者將滑鼠指標停留在控制項文字中的單字上時執行工作,這會很有用。This can be useful if you want to perform tasks when the user rests the mouse pointer over a word in the text of the control.

重要

如果指定的位置不在控制項的用戶端矩形內,或超過控制項中的最後一個字元,則傳回值會是最後一個字元的索引。If the specified location is not within the client rectangle of the control, or is beyond the last character in the control, the return value is the index of the last character.

適用於

另請參閱