通过像素坐标管理文本内容 [英] managing text content by pixel coordinates

查看:57
本文介绍了通过像素坐标管理文本内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

We would create a custom notepad. Managing by our own selection task, insert task and so on by code, without using mouse events. To be more clear, we would define a pixel position by code and insert a string in that position. Creating one textbox from scratch (implementing font layout) sounds to be really a huge work. So, we are investigating the idea to extend a richtextbox (or a textbox at least), and managing selection and insertion by code while it is disable. Following that idea, we saw textbox class show a method called GetCharacterIndexFromPoint. This method could be an initial way to achieve position into the text by screen pixel coordinates. Unfortunately that method is not available in richtextbox.

推荐答案

您好,DanielTomasini,

Hi DanielTomasini,

RichTextBox中没有使用GetCharachterIndexFromPoint的类似方法,如果要实现此目标,则必须基于TextPointer(CaretPosition)和GetOffsetToPosition进行计算,然后从元素的开头开始计算字符 或文档到TextPointer(Position),很抱歉,我没有提出更好或更简单的方法.

There is no similar method with GetCharachterIndexFromPoint in RichTextBox, if you want to achieve this goal, you have to calculate it based on TextPointer(CaretPosition) and GetOffsetToPosition, and then count the characters from start of Element or Document to TextPointer(Position), I am sorry that I have not come up with a better or simpler approach.

 

最好的问候


这篇关于通过像素坐标管理文本内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆