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


C# TextBox.GetCharacterIndexFromPoint方法代码示例

本文整理汇总了C#中System.Windows.Controls.TextBox.GetCharacterIndexFromPoint方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.GetCharacterIndexFromPoint方法的具体用法?C# TextBox.GetCharacterIndexFromPoint怎么用?C# TextBox.GetCharacterIndexFromPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.TextBox的用法示例。


在下文中一共展示了TextBox.GetCharacterIndexFromPoint方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PlaceCaretOnTextBox

 private static bool PlaceCaretOnTextBox(TextBox textBox, Point position)
 {
     int characterIndexFromPoint = textBox.GetCharacterIndexFromPoint(position, false);
     if (characterIndexFromPoint >= 0)
     {
         textBox.Select(characterIndexFromPoint, 0);
         return true;
     }
     return false;
 }
开发者ID:569550384,项目名称:Rafy,代码行数:10,代码来源:StringPropertyEditor.cs

示例2: GetCaretIndexFromPoint

		private static int GetCaretIndexFromPoint(TextBox textBox, Point point)
		{
			var index = textBox.GetCharacterIndexFromPoint(point, true);

			if (index != textBox.Text.Length - 1)
				return index;

			var caretRect = textBox.GetRectFromCharacterIndex(index);
			var caretPoint = new Point(caretRect.X, caretRect.Y);

			if (point.X > caretPoint.X)
				index += 1;

			return index;
		}
开发者ID:kknet,项目名称:StockSharp,代码行数:15,代码来源:CompositeSecurityPanel.xaml.cs

示例3: GetCharacterIndexFromPoint

        // This method is to workaround the fact that textbox.GetCharacterIndexFromPoint returns the caret
        // to the left of the character... Thus you can never get the caret after the last character in the
        // expression string.
        int GetCharacterIndexFromPoint(TextBox textbox)
        {
            Point position = Mouse.GetPosition(textbox);
            int index = textbox.GetCharacterIndexFromPoint(position, false);

            if (index < 0)
            {
                // May have clicked outside the text area, get the index of nearest char
                index = textbox.GetCharacterIndexFromPoint(position, true);
                if (index < 0)
                {
                    index = 0;
                }

                // Adjust the cursor position if we clicked to the right of returned character
                Rect charRect = textbox.GetRectFromCharacterIndex(index, true);
                if (position.X > charRect.Left + charRect.Width / 2)
                {
                    index++;
                }
            }

            return index;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:27,代码来源:VisualBasicEditor.xaml.cs


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