Counting Richtextbox visible lines with no text
Counting Richtextbox visible lines with no text
Counting Richtextbox visible lines with no text
Counting Richtextbox visible lines with no text
Counting Richtextbox visible lines with no text
Counting Richtextbox visible lines with no text Counting Richtextbox visible lines with no text Counting Richtextbox visible lines with no text Counting Richtextbox visible lines with no text Counting Richtextbox visible lines with no text Counting Richtextbox visible lines with no text Counting Richtextbox visible lines with no text Counting Richtextbox visible lines with no text
Counting Richtextbox visible lines with no text Counting Richtextbox visible lines with no text
Counting Richtextbox visible lines with no text
Go Back  Xtreme Visual Basic Talk > > > Counting Richtextbox visible lines with no text


Reply
 
Thread Tools Display Modes
  #1  
Old 02-11-2014, 08:16 AM
n2amg n2amg is offline
Junior Contributor
 
Join Date: Aug 2001
Posts: 279
Default Counting Richtextbox visible lines with no text


I have a richtextbox on one of my forms and I need to know how many lines of text will be visible in the rtb before I put any text into it. Is there a way to do it using the RTB.heigth, rtb.width, and the font size?

Thanks
Rick
Reply With Quote
  #2  
Old 02-11-2014, 09:23 AM
Gruff's Avatar
GruffCounting Richtextbox visible lines with no text Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

There are several things that can affect visible line count. (Whether there is text or not)

The zoom property will show a different number of lines to your eye.

The control can also be a size that allows partial lines to be displayed at the bottom. Even though it may look like you have an extra line than that reported by the following code it may be that the partial line is like 99% of full height.

The Wordwrap property can factor in depending on what you want to do.

Finally I have had trouble with getting good results if the font is changed at run-time.

Code:
Public Class Form1 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click With RichTextBox1 Using g As Graphics = .CreateGraphics Dim LineHt As Single = g.MeasureString("Ij", .Font, 100).Height Dim VisibleLines As Integer = CInt(.DisplayRectangle.Height / LineHt) MessageBox.Show(VisibleLines.ToString) End Using End With End Sub Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 'Put some lines of text in to check. For i = 1 To 24 RichTextBox1.Text &= i.ToString & Environment.NewLine Next End Sub End Class
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #3  
Old 02-11-2014, 10:32 AM
n2amg n2amg is offline
Junior Contributor
 
Join Date: Aug 2001
Posts: 279
Default

That seems to work for what I am doing. I have had only one time it was off and that was the way the form was resized.

One thing I should have asked I had forgot about is there a way like this to also calculate the number of characters that each line should hold?
I have never worked with g.MeasureString("Ij", .Font, 100).Height will it also work for .width?

TIA
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Counting Richtextbox visible lines with no text
Counting Richtextbox visible lines with no text
Counting Richtextbox visible lines with no text Counting Richtextbox visible lines with no text
Counting Richtextbox visible lines with no text
Counting Richtextbox visible lines with no text
Counting Richtextbox visible lines with no text Counting Richtextbox visible lines with no text Counting Richtextbox visible lines with no text Counting Richtextbox visible lines with no text Counting Richtextbox visible lines with no text Counting Richtextbox visible lines with no text Counting Richtextbox visible lines with no text
Counting Richtextbox visible lines with no text
Counting Richtextbox visible lines with no text
 
Counting Richtextbox visible lines with no text
Counting Richtextbox visible lines with no text
 
-->