Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15539

VS 2013 How Can I get MultiLine TextBox Line count ? (straight text)

$
0
0
hi Everyone...

There is a TextBox which MultiLine =True and ScrollBars = NONE

I enter a straight Text in TextBox. without Press Enter adding new line into TextBox.

I try to Get Lines Count but I couldnt success. I search almost all sample codes but not success.

Mostly give me 1 line less, sometimes give correct. but I couldnt get the solution.

Even has 3 or 4 lines this code gives always 1 line

Dim lineCount As Integer = TextBox1.Lines.Count


Code:

Private Function CountLines() As Integer
        Dim g As Graphics = TextBoxKontrol.CreateGraphics()
        Dim sf As StringFormat = DirectCast(System.Drawing.StringFormat.GenericTypographic.Clone(), StringFormat)
        sf.Alignment = StringAlignment.Near
        sf.FormatFlags = StringFormatFlags.NoClip
        Dim charCount As Integer
        Dim lineCount As Integer
        Call g.MeasureString(TextBoxKontrol.Text, TextBoxKontrol.Font, New SizeF(TextBoxKontrol.Width, TextBoxKontrol.Height), sf, charCount, lineCount)
        g.Dispose()
        Return lineCount
    End Function

    Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click

        MsgBox(CountLines)
     
    End Sub

And the TEXT that I put in TextBox is

"Hazreti Omer Mahallesi Turk Ulusu Caddesi Serdengecti Sokak Numara: 10 Daire: 4"

Viewing all articles
Browse latest Browse all 15539

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>