devxlogo

Counting Lines in RichTextBox

Counting Lines in RichTextBox

Question:
I want to develop a word-processor with VB 4.0 and the RichTextBox. I’ve got all the functions like bold, italic etc. but I’m missing a function to count the pages. Is there any function in VB 4.0 to count the pages or do I have do write my own function?

Answer:
After checking the RichTextBox help, the only thing I found was the GetLineFromChar method. It tells you what line a particular character number is. You could do something like this:

Dim iLines as LongiLines = RichTextBox.GetLineFromChar(Len(RichTextBox.Text))
That should give you the total number of lines in the document. You can then divide that by 66 or however many lines there are on your page, with a given font size.

devx-admin

Share the Post: