How to get the number of richtextbox?

zhaozj2021-02-12  174

Start with the following method: Dim r As RichTextBox = RichTextBox1 Dim lines, iFirst, iLast As Int32 iFirst = r.GetLineFromCharIndex (r.GetCharIndexFromPosition (New Point (0, 0))) iLast = r.GetLineFromCharIndex (r.GetCharIndexFromPosition (New Point (0, R.HEIGHT)) LINES = Ilast - IFirst MessageBox.Show (Lines) But found not very accurate, if the scroll bar is the correct number of rows when the scroll bar is in the middle, if there is no character in RichTextBox, or characters There are many, it is not right when there is no scroll bar.

The following method can:

Dimg as graphics g = richtextbox1.creategraphics () lines = richtextbox1.height / g.MeasureString ("test", richtextbox1.font) .height () MessageBox.show (Lines)

转载请注明原文地址:https://www.9cbs.com/read-7442.html

New Post(0)