RichTextBox – Visual Studio [英] RichTextBox в Visual Studio

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

问题描述

您能告诉我们如何确定RichTextBox中当前可见的行数吗?"

"Can you tell how to determine numbers of lines which currently are visible in RichTextBox?"

推荐答案

不好,但是...
尝试以下操作:
Not nice, but...
Try this:
int top = myRichTextBox.GetCharIndexFromPosition(new Point(1, 1));
int bottom = myRichTextBox.GetCharIndexFromPosition(new Point(1, myRichTextBox.Height - 1));

int topLine = myRichTextBox.GetLineFromCharIndex(top);
int bottomLine = myRichTextBox.GetLineFromCharIndex(bottom);

int linesDisplayed = bottomLine - topLine;
Console.WriteLine("{0}:{1} = {2}", topLine, bottomLine, linesDisplayed);


以及该代码如何:
and how about this one:
int charCount;
int lineCount;
this.CreateGraphics().MeasureString(
    richTextBox1.Text, 
    richTextBox1.Font,
    new SizeF(richTextBox1.Width, richTextBox1.Height),
    new StringFormat(StringFormatFlags.FitBlackBox), 
    out charCount, 
    out lineCount);


lineCount-1值似乎是正确的可见行数


the lineCount-1 value seems to be the correct visible lines count


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

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