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


C# TextBox.GetPositionFromCharIndex方法代码示例

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


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

示例1: pathFits

 public static bool pathFits(string path, TextBox text)
 {
     string tempPath = text.Text;
     int prefLoc = text.Right - text.Location.X;
     text.Text = path + "[]";
     int currentLoc = text.GetPositionFromCharIndex(text.Text.Length - 1).X;
     text.Text = tempPath;
     return currentLoc < prefLoc;
 }
开发者ID:DeepDolphin,项目名称:CameraSorterVisual,代码行数:9,代码来源:Program.cs

示例2: MakeEndOfTextVisibleAndFocus

		/// <summary>
		/// Make sure that the end of the text in the given text box is visible.
		/// An (undesired) side effect is to focus the box and put the selection at the end of it.
		/// I cannot find any portable way to achieve the desired scrolling without doing this.
		/// </summary>
		/// <param name="textBox"></param>
		private void MakeEndOfTextVisibleAndFocus(TextBox textBox)
		{
			if (textBox.Text.Length == 0)
				return;
			// It would seem logical that we would not want the -1, so we would be asking for the position of the
			// imaginary character at the very end. However, that just always returns (0,0).
			Point endPosition = textBox.GetPositionFromCharIndex(textBox.Text.Length - 1);
			if (endPosition.X > textBox.Width)
			{
				textBox.Focus();
				textBox.Select(textBox.Text.Length, 0);
				textBox.ScrollToCaret();
			}
		}
开发者ID:sillsdev,项目名称:FieldWorks,代码行数:20,代码来源:InterlinearSfmImportWizard.cs

示例3: RetrieveHotSpots_NoHotspotsReturned_NoHotSpotsVisible

		public void RetrieveHotSpots_NoHotspotsReturned_NoHotSpotsVisible()
		{
			using (TextBox textBox = new TextBox())
			{
				textBox.Text = "Now is the time.";
				_hotSpotProvider.SetEnableHotSpots(textBox, true);
				_hotSpotProvider.RetrieveHotSpots += delegate
														 {
															 // give back no hot spots
														 };

				//if we scan the entire text for hot spots we shouldn't find any
				for (int i = 0;i != textBox.Text.Length;++i)
				{
					Point position = textBox.GetPositionFromCharIndex(i);
					List<HotSpot> hotSpots =
						new List<HotSpot>(
							_hotSpotProvider.GetHotSpotsFromPosition(textBox, position));
					Assert.AreEqual(0, hotSpots.Count);
				}
			}
		}
开发者ID:JohnThomson,项目名称:libpalaso,代码行数:22,代码来源:HotSpotProviderTests.cs

示例4: RetrieveHotSpots_GiveSomeHotspots_HotSpotsVisible

	[NUnit.Framework.Category("KnownMonoIssue")] // review: WS-????
	public void RetrieveHotSpots_GiveSomeHotspots_HotSpotsVisible()
	{
			using (TextBox textBox = new TextBox())
			{
				textBox.Text = "Now is the time for all good men to come to the aid...";
				_hotSpotProvider.SetEnableHotSpots(textBox, true);
				_hotSpotProvider.RetrieveHotSpots +=
					delegate(object sender, RetrieveHotSpotsEventArgs e)
						{
							e.AddHotSpot(new HotSpot(e.Control, 7, 3));
							e.AddHotSpot(new HotSpot(e.Control, 16, 3));
						};

				Point position = textBox.GetPositionFromCharIndex(8);
				List<HotSpot> hotSpots =
					new List<HotSpot>(
						_hotSpotProvider.GetHotSpotsFromPosition(textBox, position));
				Assert.AreEqual(1, hotSpots.Count);
				Assert.AreEqual(7, hotSpots[0].Offset);
				Assert.AreEqual("the", hotSpots[0].Text);

				position = textBox.GetPositionFromCharIndex(16);
				hotSpots =
					new List<HotSpot>(
						_hotSpotProvider.GetHotSpotsFromPosition(textBox, position));
				Assert.AreEqual(1, hotSpots.Count);
				Assert.AreEqual(16, hotSpots[0].Offset);
				Assert.AreEqual("for", hotSpots[0].Text);
			}
		}
开发者ID:JohnThomson,项目名称:libpalaso,代码行数:31,代码来源:HotSpotProviderTests.cs

示例5: 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

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