当前位置: 首页>>代码示例>>C#>>正文


C# TextBox.GetCharIndexFromPosition方法代码示例

本文整理汇总了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;
		}
开发者ID:jwickberg,项目名称:libpalaso,代码行数:22,代码来源:BetterGrid.cs

示例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;
		}
开发者ID:jwickberg,项目名称:libpalaso,代码行数:26,代码来源:BetterGrid.cs


注:本文中的System.Windows.Forms.TextBox.GetCharIndexFromPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。