Advertisement

04.19.2007 at 07:15PM PDT, ID: 22523019
[x]
Attachment Details

Overriding grey text on a disabled VB.NET TextBox

Asked by amaximia in .NET, .Net Editors & IDEs, Visual Studio .NET 2005

Tags: textbox, disabled

I'm trying to display memo text in a box whereupon the user cannot select and copy the text out.  I drew a textbox and set enabled = false but the text turned grey and hard to read:

            Dim tpOrigin As New TabPage
            tpOrigin.Text = "Origin"
                Dim text1 As New TextBox
                tpOrigin.Controls.Add(text1)
                text1.Location = New System.Drawing.Point(8, 8)
                text1.BackColor = Color.White
                text1.ForeColor = Color.DarkBlue
                text1.Multiline = True
                text1.Size = New System.Drawing.Size(720, 156)
                text1.Enabled = False
                text1.Text = memo
             tabBaker.TabPages.Add(tpOrigin)

So I decided to create my own textbox class called visualtextbox:

    Public Class VisualTextbox
        Inherits TextBox

        Public Sub New()
            ' Initialise the class
            MyBase.New()
        End Sub

        Public Shadows Property Enabled() As Boolean
            Get
                Return MyBase.Enabled
            End Get
            Set(ByVal Value As Boolean)
                ' Switch draw styles if disabled
                Me.SetStyle(ControlStyles.UserPaint, Not Value)
                ' Set the underlying value
                MyBase.Enabled = Value
            End Set
        End Property

        Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
            MyBase.OnPaint(e)

            ' Draw the bg in
            e.Graphics.FillRectangle(New SolidBrush(Me.BackColor), Me.ClientRectangle)

            ' Draw the appropriate text in using the fore color
            e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Me.ForeColor), -1, 1)
        End Sub

    End Class

And changed the code to the following:

            Dim tpOrigin As New TabPage
            tpOrigin.Text = "Origin/Habitat"
                Dim text1 As New VisualTextbox
                tpOrigin.Controls.Add(text1)
                text1.Location = New System.Drawing.Point(8, 8)
                text1.BackColor = Color.White
                text1.ForeColor = Color.DarkBlue
                text1.Multiline = True
                text1.Size = New System.Drawing.Size(720, 156)
                text1.Enabled = False
                text1.Text = memo
            tabBaker.TabPages.Add(tpOrigin)

The problem I have now in the text is not wraping around no matter what I do.  I've tried setting wordwrap to true, multiline, etc., but nothing seems to work.  Any ideas?

Thanks.
Start Free Trial
[+][-]04.19.2007 at 07:19PM PDT, ID: 18943788

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.19.2007 at 07:49PM PDT, ID: 18943862

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET, .Net Editors & IDEs, Visual Studio .NET 2005
Tags: textbox, disabled
Sign Up Now!
Solution Provided By: Idle_Mind
Participating Experts: 4
Solution Grade: A
 
 
[+][-]04.19.2007 at 08:09PM PDT, ID: 18943916

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04.19.2007 at 08:23PM PDT, ID: 18943965

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.19.2007 at 08:29PM PDT, ID: 18943982

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.19.2007 at 08:37PM PDT, ID: 18944005

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.19.2007 at 08:48PM PDT, ID: 18944051

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2007 at 01:23AM PDT, ID: 18944827

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2007 at 04:23AM PDT, ID: 18945430

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2007 at 04:28AM PDT, ID: 18945447

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2007 at 04:49AM PDT, ID: 18945520

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2007 at 05:30AM PDT, ID: 18945730

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04.20.2007 at 05:33AM PDT, ID: 18945748

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2007 at 06:15AM PDT, ID: 18946076

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2007 at 06:44AM PDT, ID: 18946259

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2007 at 07:02AM PDT, ID: 18946409

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2007 at 07:06AM PDT, ID: 18946449

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2007 at 08:09AM PDT, ID: 18947016

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2007 at 08:45AM PDT, ID: 18947296

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2007 at 09:01AM PDT, ID: 18947429

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2007 at 09:03AM PDT, ID: 18947440

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2007 at 09:20AM PDT, ID: 18947593

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2007 at 11:51AM PDT, ID: 18948682

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2007 at 11:52AM PDT, ID: 18948685

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2007 at 11:54AM PDT, ID: 18948701

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2007 at 04:18PM PDT, ID: 18950197

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32