编程方式移动在文本框中插入符号,线和线下行 [英] programmatically move caret in textbox, line up and line down

查看:569
本文介绍了编程方式移动在文本框中插入符号,线和线下行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我奋力插入符号在文本编辑控制一个DataGridView 中,一条线和一条线下来,就如同用户将获得按上下箭头的时候。



所以,我的意思并不是作为行是什么换行符之间,我的意思是行作为什么是文本框的左侧和右侧之间。



我不能使用GetCharIndexFromPosition和GetPositionFromCharIndex,因为不是所有的文字总是会在文本框中显示区显示



编辑:
,因为我处理一个DataGridView内的文本框格老子不能模拟的KeyPress。我的目的其实是让箭头键做自己会做一个正常的文本框的东西,而不是从行与行跳。


解决方案
< 。p>这应该工作

 点POLD = textBox1.GetPositionFromCharIndex(textBox1.SelectionStart); 
点Pnew最多=新的点(pOld.X,pOld.Y + textBox1.Font.Height)
INT的charIndex = textBox1.GetCharIndexFromPosition(Pnew最多);
textBox1.SelectionStart = charIndex处;



我不认为这是最干净的解决方案,但。也许你应该考虑在DataGridView性能/按键处理。


I am struggling to move the caret in a textbox editing control within a DataGridView, one line up and one line down, just as a user would get when pressing up and down arrows.

So I don't mean lines as what is between newline characters, I mean lines as what is between the left and right side of a textbox.

I cannot use GetCharIndexFromPosition and GetPositionFromCharIndex because not all text will always be shown in the textbox display area.

Edit: I cannot simulate KeyPress because I am dealing with a textbox cell within a DataGridView. My aim is in fact getting arrow keys to do what they would do in a normal textbox, instead of jumping from row to row.

解决方案

This should work.

Point pOld = textBox1.GetPositionFromCharIndex(textBox1.SelectionStart);
Point pNew = new Point(pOld.X, pOld.Y + textBox1.Font.Height)
int charIndex = textBox1.GetCharIndexFromPosition(pNew);
textBox1.SelectionStart = charIndex;

I don't think it's the cleanest solution though. Maybe you should look into the DataGridView properties/key handling.

这篇关于编程方式移动在文本框中插入符号,线和线下行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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