Results 1 to 5 of 5

Thread: [2008] Disabled multi-line text box that's scrollable... possbile?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    29

    Question [2008] Disabled multi-line text box that's scrollable... possbile?

    Is it possible to make a multi-line text box still scrollable while it's disabled?

    The closest I can achieve this is to set the text box's ReadOnly property to false, which will gray out the text box, and still scrollable, but the text in the box remains black instead of being gray. Changing the forecolor of the text box does not have any effect. The color of the text changes back to black when I set ReadOnly to true.

    I want to be able to mimic the disabled text box visually. Thanks for the help!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Disabled multi-line text box that's scrollable... possbile?

    It's not possible. Disabled means disabled. Perhaps if you were to inherit the class and mess around with the internals but I wouldn't like to hazard a guess as to what exactly you'd need to do.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Member
    Join Date
    Jun 2008
    Posts
    42

    Re: [2008] Disabled multi-line text box that's scrollable... possbile?

    you could just make a small function that works on a timer ticking (set the tick timer to, say, 10) and then use this

    Code:
    textbox1.clear()
    textbox1.text = "put your original text here)
    This will reset the text whenever the timer ticks

    Hope it helps

    Ryy
    currently studying on a VB course as well as part time self teaching C#

  4. #4
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [2008] Disabled multi-line text box that's scrollable... possbile?

    Quote Originally Posted by ryytikki
    you could just make a small function that works on a timer ticking (set the tick timer to, say, 10) and then use this

    Code:
    textbox1.clear()
    textbox1.text = "put your original text here)
    This will reset the text whenever the timer ticks

    Hope it helps

    Ryy
    Thats a really bad way of doing it in my opinion. For one thing having a timer running every 10 ms has got to have some kind of impact on performance and for another thing it is just plain bad design. You would probably also find that the text appears to be constantly flickering if its getting cleared and reset every 10 miliseconds.


    The way I would do it would be to just set the forecolor and backcolor manually and leave the ReadOnly property as False, then just use the KeyDown event like this to stop users being able to type into it:

    vb.net Code:
    1. Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
    2.         e.SuppressKeyPress = True
    3. End Sub
    Last edited by chris128; Jan 16th, 2009 at 06:09 AM.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


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

    Re: [2008] Disabled multi-line text box that's scrollable... possbile?

    vb.net Code:
    1. Public Class Form1
    2.     Inherits System.Windows.Forms.Form
    3.  
    4.     Private Sub Form1_Load( _
    5.         ByVal sender As System.Object, _
    6.         ByVal e As System.EventArgs _
    7.     ) Handles MyBase.Load
    8.  
    9.         CustomTextBox1.ReadOnly = True
    10.         CustomTextBox1.BackColor = Color.White
    11.         CustomTextBox1.ForeColor = Color.Gray
    12.     End Sub
    13. End Class
    14.  
    15. Public Class CustomTextBox
    16.     Inherits TextBox
    17.  
    18.     Protected Overrides Sub OnPaint( _
    19.         ByVal e As System.Windows.Forms.PaintEventArgs _
    20.     )
    21.         Dim brush As SolidBrush = New SolidBrush(ForeColor)
    22.         e.Graphics.DrawString(Text, Font, brush, 0.0F, 0.0F)
    23.     End Sub
    24.  
    25.     Public Sub New()
    26.         MyBase.New()
    27.         Me.SetStyle(ControlStyles.UserPaint, True)
    28.     End Sub
    29. End Class

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