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(text
1)
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(tpOr
igin)
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.Paint
EventArgs)
MyBase.OnPaint(e)
' Draw the bg in
e.Graphics.FillRectangle(N
ew SolidBrush(Me.BackColor), Me.ClientRectangle)
' Draw the appropriate text in using the fore color
e.Graphics.DrawString(Me.T
ext, 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(text
1)
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(tpOr
igin)
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