RichTextBox的大小 [英] Size of RichTextBox

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

问题描述

你好,
我正在编写一个大型日志文件查看器.所以,我有2个问题:
1.如何获取Richtextbox的实际大小? (带有不可见的滚动"区域)
2.如何只删除一部分RichTextBox(顶部或底部的文本占全文的百分比)?

Hello,
I''m coding a big log file viewer. So, I have 2 questions:
1. How I can get the actual size of richtextbox? ( with invisible "scrolling" area)
2. How I can delete only a part of richtextbox ( top or bottom text in percent of full text)?

推荐答案

我不确定那是什么您要在 1.中提出要求.如果需要的话,所有控件都具有Size属性.但是,我怀疑您的意思是可用于文本的区域的大小.

我能想到的唯一方法是对 EM_GETRECT消息使用P/Invoke [ ^ ].我没有尝试过,所以不能保证.

2.而言,这取决于您是否需要行数,单词数或字符数的百分比.


richtextbox具有Lines属性,而MyRTB.Lines.Length将为您提供值.

单词
这是一个WordCount方法.

I''m not sure what it is that you are asking for in 1.. All Controls have a Size property, if that is what you want. I suspect, however, that you mean the size of the area available for text.

The only way that I can think of is to use P/Invoke with the EM_GETRECT Message[^]. I''ve not tried it, so no guarantees.

As far as 2. is concerned, it depends on whether you want a percentage of the number of lines, the number of words or the number of characters.

Lines
The richtextbox has a Lines property and MyRTB.Lines.Length will give you the value.

Words
Here is a WordCount Method.

private int GetWordCount()
{
    // Add space to end of text to ensure the last word is counted.
    MatchCollection wordColl = Regex.Matches(richTextBox1.Text, @"[\W]+");
    return wordColl.Count;
}



字符
myRTB.TextLength可能足以满足您的需求.

在所有情况下,快速的数学运算都将为您解答.

删除文本的方法很多,但是最简单的方法之一是使用 myRTB.Text.Remove(int) [



Characters
myRTB.TextLength may be enough for what you need.

In all cases a quick bit of math will get your answer.

For deleting the text there are many methods but one of the easiest is to use the myRTB.Text.Remove(int)[^] method, or one of its'' overrides.


我不确定这是否是您要的内容,但是RichTextBox有一个Line成员,您可以在其中获得一个包含文本行的字符串数组.如果获得此数组的Length成员,则控件中将具有行数.这与文本的可见部分无关.如果您需要以点或像素为单位的大小,则需要查找使用的字体,我认为.

使用此信息,您可以计算要删除的行的百分比.

我还没有尝试过,但是我认为这应该可行
I am not sure if this is what you asked for, but the RichTextBox has a Line member where you can get a string array containig the Lines of the Text. If you get the Length member of this array you have the number of lines in your control. This is independend of the visible portion of the text. If you need the size in points or pixels the you need to look up what font is used I think.

With this information you can calculate the percentage of lines to delete.

I haven''t tried this, but I think this schould work


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

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