TextBoxBase.GetCharIndexFromPosition(Point) 方法

定義

擷取最接近指定位置之字元的索引。

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

要搜尋的位置。

傳回

指定位置處的以零為起始的字元索引。

備註

這個方法會傳回最接近參數中所指定位置的 pt 字元索引。 字元索引是控制項中文字以零起始的索引,包括空格。 您可以使用這個方法,藉由將滑鼠座標傳遞至這個方法,來判斷使用者文字中的滑鼠停留位置。 如果您想要在使用者將滑鼠指標放在控制項文字中的文字上,執行工作時,這會很有用。

重要

如果指定的位置不在控制項的用戶端矩形內,或超出控制項的最後一個字元,則傳回值是最後一個字元的索引。

適用於

另請參閱