Results 1 to 2 of 2

Thread: Need a textbox that displays all lines w/o scrolling

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    523

    Need a textbox that displays all lines w/o scrolling

    I can put a long text string in a label, and it will automatically adjust the size to fit the text. Unfortunately, it does not recognize carriage returns. The text box does recognize the returns, but I have to tell it how many lines I want.

    Is there some way of having the best of both? Can I set a property that would accomplish this. (I could not find it, if it exists). Is there some other object that would be better?

    Sorry I posted this in the wrong Place. I am dealing with ASP.net 2008
    Last edited by John_SC; Aug 8th, 2008 at 05:37 AM. Reason: Question posted in wrong place

  2. #2
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: Need a textbox that displays all lines w/o scrolling

    vb.net Code:
    1. Public Class Form2
    2.  
    3.     Private Sub Form2_Load( _
    4.         ByVal sender As System.Object, _
    5.         ByVal e As System.EventArgs _
    6.     ) Handles MyBase.Load
    7.  
    8.         TextBox1.Multiline = True
    9.         TextBox1.WordWrap = False
    10.     End Sub
    11.  
    12.     Private Sub Button1_Click( _
    13.         ByVal sender As System.Object, _
    14.         ByVal e As System.EventArgs _
    15.     ) Handles Button1.Click
    16.  
    17.         Dim myFont As New Font(TextBox1.Font.Name, TextBox1.Font.Size)
    18.         Dim StringSize As New SizeF
    19.         Dim littleAdjustment As Integer = 1
    20.  
    21.         StringSize = Me.CreateGraphics.MeasureString(TextBox1.Text.Substring(1, 1), myFont)
    22.         TextBox1.Height = StringSize.Height * (TextBox1.Lines.GetUpperBound(0) + littleAdjustment)
    23.     End Sub
    24.  
    25. End Class
    How is this?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width