Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取WPF中文本框中文本的第一个字符的位置(x,y)_C#_Wpf_Textbox_Position_Point - Fatal编程技术网

C# 获取WPF中文本框中文本的第一个字符的位置(x,y)

C# 获取WPF中文本框中文本的第一个字符的位置(x,y),c#,wpf,textbox,position,point,C#,Wpf,Textbox,Position,Point,如何将文本框中的第一个字符索引转换为WPF中的x,y坐标ie基本上我需要WPF中文本框中第一个字符的点移动。我正在捕获WPF窗口屏幕上显示的文本框wrt图像的x,y坐标 UIElement容器=(MainImage)作为UIElement;System.Windows.Point relativeLocation=textboxinsert.TranslatePoint(新的System.Windows.Point(0,0),容器) 但不知道如何在wpf中对文本框中的文本执行此操作。任何指针都会

如何将文本框中的第一个字符索引转换为WPF中的x,y坐标ie基本上我需要WPF中文本框中第一个字符的点移动。我正在捕获WPF窗口屏幕上显示的文本框wrt图像的x,y坐标
UIElement容器=(MainImage)作为UIElement;System.Windows.Point relativeLocation=textboxinsert.TranslatePoint(新的System.Windows.Point(0,0),容器)

但不知道如何在wpf中对文本框中的文本执行此操作。任何指针都会非常有用吗?

如果只需要找到第一次出现的位置,则可以使用
textbox.text.IndexOf('x')

如果您也需要行,则需要在因文本框大小而中断的行与因用户按Enter键而中断的行之间进行区分


您可以通过使用MemoryStream和StreamReader来实现这一点。

您可以使用这些,您需要更具体一些。。。为什么你需要第一个字符的坐标,你想用它做什么,这是因为边距和填充物或者类似的东西。因为讽刺的是,这听起来像是一个X,Y问题@styx GetPositionFromCharIndex只能在winforms中工作wpf@MichaelRandall我想在图像上插入一段文字我需要x,文本框中第一个字符的y坐标,以便我可以在图像上绘制它。我可以捕获文本框左上角的坐标,但不能捕获文本。边距,填充都设置为0。任何建议都会非常有用嗯,这是我的想法,拇指Up@agent_Orange:感谢您的回复,但我不需要明确提到的索引。我需要在中的文本框中获取字符的X,Y坐标wpf@krishnaa请看我答案的第二和第三段。您可以使用StreamReader.ReadLine()将文本加载到MemoryStream和中;绕线走。但请注意,换行符仅因文本框的大小而存在。它们不会被注意到。@krishnaa嗯,你能告诉我,你想要x和y坐标,但参考什么?ie你知道那个角色在destop屏幕上的什么位置吗?@Agent_Orange-我可以将文本框左上角的(x,y)捕捉到显示的图像<代码>UIElement容器=(MainImage)作为UIElement;System.Windows.Point relativeLocation=textboxinsert.TranslatePoint(新的System.Windows.Point(0,0),容器)。但是我需要文本框中第一个字符的x,y