文字框 [英] TextBox.Text

查看:102
本文介绍了文字框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该怎么办

获取TextBox.Text的y位置

我的意思是:

我有一个带有滚动条的文本框

写入邮件的地方

//在文本框中

你好,你好吗?

怎么了?

bla bla bla ...

//现在在这个位置,我想附加一个按钮控件
//但我无法确定如何获得在
中设置控件的位置 //我正在寻找某种类型的线索引类型属性

how would i go about

getting the y position of a TextBox.Text

what i mean is as follows :

i have a textbox with scroller

messages where writen to it

// inside the textbox

hello how are u?

whats up?

bla bla bla...

// now in this position i would like to append a button control
// but i cant fingure out how to get the position to set the control in
// im looking for somthing sort of a line index type property

rtb_msg.Controls.Add(x_panel);
x_panel.Location = new Point(rtb_send.Width / 2 -x_panel.Width / 2,??? <big>Height</big> ???);

推荐答案

原则上,您可以这样做.您可以在需要的位置重现完全相同的文本并计算文本度量.
从这里开始:
http://www.devsource.com/c /a/Languages/Text-Metrics-in-the-Net-Framework-Part-I/ [别这么做!

这是一个非常非常糟糕的主意.您将花费不成比例的长时间以获得非常不可靠的结果.当您执行此操作时,您将必须努力使您的编辑控件在聚焦时位于按钮顶部—哪个事件应该再次将您的按钮显示在顶部?您将不得不捕获滚动文本(您提到过滚动自己)或修改文本的所有事件,因为其中任何一个都会弄乱您的布局.

最有可能的是,您将得到满意的行为比从来没有迟一点:).
In principle, you could do it. You can reproduce exact same text up the the point you need and calculate text metrics.
This is where to start:
http://www.devsource.com/c/a/Languages/Text-Metrics-in-the-Net-Framework-Part-I/[^], but...

Don''t do it!



This is a very, very bad idea. You''re going to spend disproportionally long time to obtain very unreliable result. When you do it, you will have to struggle will your edit control going on top of your button when focused -- what event should be showing your button on top again? you will have to catch all events of scrolling the text (you mentioned scrolling yourself) or modification of the text, because any of those will mess up your layout.

Most likely, you will get the satisfactory behavior a little later than never :) .


SAKryukov是正确的-您将花费很多精力来降低成本奖励.

您是否考虑过改用GridView或DataGridView?如果您有一个文本列和一个按钮列,那么它们将保持在一起.
SAKryukov is right - you will expend a lot of effort for a very low reward.

Have you considered using a GridView or a DataGridView instead? If you have a text column and a button column, that would keep them together.


这篇关于文字框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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