本文整理汇总了C#中System.Windows.Forms.TextBox.GetCharIndexFromPosition方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.GetCharIndexFromPosition方法的具体用法?C# TextBox.GetCharIndexFromPosition怎么用?C# TextBox.GetCharIndexFromPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.TextBox
的用法示例。
在下文中一共展示了TextBox.GetCharIndexFromPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessDownKey
/// ------------------------------------------------------------------------------------
/// <summary>
/// Processes down key when a grid cell is in the edit mode. This overrides the default
/// behavior in a grid cell when it's being edited so using the down arrow will move the
/// IP down one line rather than moving to the next row.
/// </summary>
/// ------------------------------------------------------------------------------------
protected virtual bool ProcessDownKey(TextBox txtBox)
{
// Don't override the default behavior if all the text is selected or not multi-line.
if (txtBox.SelectedText == txtBox.Text || !txtBox.Multiline)
return false;
int chrIndex = txtBox.SelectionStart;
Point pt = txtBox.GetPositionFromCharIndex(chrIndex);
pt.Y += TextRenderer.MeasureText("x", txtBox.Font).Height;
var proposedNewSelection = txtBox.GetCharIndexFromPosition(pt);
if (proposedNewSelection <= chrIndex)
return false; // Don't let "down" take you *up*. (See SP-220.)
txtBox.SelectionStart = proposedNewSelection;
return true;
}
示例2: ProcessUpKey
/// ------------------------------------------------------------------------------------
/// <summary>
/// Processes up key when a grid cell is in the edit mode. This overrides the default
/// behavior in a grid cell when it's being edited so using the up arrow will move the
/// IP up one line rather than moving to the previous row.
/// </summary>
/// ------------------------------------------------------------------------------------
protected virtual bool ProcessUpKey(TextBox txtBox)
{
// Don't override the default behavior if all the text is selected or not multi-line.
if (txtBox.SelectedText == txtBox.Text || !txtBox.Multiline)
return false;
int selectionPosition = txtBox.SelectionStart;
// Getting the position after the very last character doesn't work.
if (selectionPosition == txtBox.Text.Length && selectionPosition > 0)
selectionPosition--;
Point pt = txtBox.GetPositionFromCharIndex(selectionPosition);
if (pt.Y == 0)
return false;
pt.Y -= TextRenderer.MeasureText("x", txtBox.Font).Height;
txtBox.SelectionStart = txtBox.GetCharIndexFromPosition(pt);
return true;
}