Just wondering out there if there is a better way to measure the contents of a richtextbox so you know how many printed pages there will be. What I really want is for a message to appear saying "You have reached the end of page 1." or something like that. I have it sorta figured out but all text has to be the same size. Does not really matter what font or what size, it just has to be one size. I would really like to be able to make a word or two a larger size but that throws everything off with the below code. I have searched and have not found anything close.
Any help would be appreciated
Thanks
Pat
Any help would be appreciated
Thanks
Pat
vb.net Code:
'Speller1 is my richtextbox Dim sz As Integer = SpellerFntSize Dim NoLines As Integer = Speller1.Lines.Count Dim txt As String = Trim(Speller1.Text) Dim txtA() As String = txt.Split(" ") Dim WrdCnt As Integer = txtA.GetUpperBound(0) + 1 Dim BoxWidth As String = ProposalSettings(9) Dim BoxWidthD As Decimal = 765 If Not IsNumeric(BoxWidth) Then BoxWidth = 765 BoxWidthD = BoxWidth Else BoxWidthD = BoxWidth End If Dim dpiX As Single Dim dpiY As Single Dim dpiR As Single Dim dpiN As Single = 1 Using g As Graphics = Me.CreateGraphics() dpiX = g.DpiX dpiY = g.DpiY End Using 'seeing if user is using large fonts If dpiX <> 96 Then dpiR = 96 dpiN = dpiX / dpiR End If 'BoxWidthD is the width of the box BoxWidthD = BoxWidthD * dpiN Dim currentFont As System.Drawing.Font = Speller1.SelectionFont Dim FntSize As Integer = currentFont.Size Dim realnumber As Integer = 0 'NoLines For i = 0 To NoLines - 1 Dim text1 As String = Speller1.Lines(i).Trim 'arialBold is not really the font, its just a var that I used to get the name of the selected font Dim arialBold As New Font(Speller1.SelectionFont.OriginalFontName, sz) Dim textSize As Size = TextRenderer.MeasureText(text1, arialBold) Dim a As Decimal = 0 Dim b As Decimal = textSize.Width If b <> 0 Then a = b / BoxWidthD a = Math.Ceiling(a) If a > 1 Then realnumber = realnumber + a Else realnumber = realnumber + 1 End If Else realnumber = realnumber + 1 End If Next 'amount is the number of lines allowed for a specific font size taken from a table I made TsLinsRm.Text = "Lines Remaining: " & Amount - realnumber Dim LinesRm As Integer = CInt(Amount - realnumber) LiveCntAmount = LinesRm If LinesRm < 3 Then TsLinsRm.ForeColor = Color.Maroon Else TsLinsRm.ForeColor = Color.DarkSlateGray End If Catch ex As Exception End Try