473,508 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Derived TextBox

Rob
Question : I want to create a read only TextBox that does not
respond to any input from the keyboard, therefore I came up
with the following derived class :

Option Strict On

Imports System.Windows.Forms.TextBox

Public Class DerivedTextBox
Inherits TextBox

Protected Overridable Sub KeyEventHandler( _
ByVal sender As Object, _
ByVal e As KeyEventHandler)

End Sub

End Class
I then place this TextBox on my Form1 using the following :

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
Me.TextBox1.Show()
'
'TextBox1
'
Me.TextBox1.AutoSize = False
Me.TextBox1.Location = New System.Drawing.Point(8, 8)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.ReadOnly = True
Me.TextBox1.Size = New System.Drawing.Size(230, 150)
Me.TextBox1.TabIndex = 1
Me.TextBox1.TabStop = False
Me.TextBox1.Text = ""
Me.TextBox1.Visible = True
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents TextBox1 As DerivedTextBox

However the TextBox remains invisible. How can I get
TextBox1 to appear on Form1 ?
Mar 28 '06 #1
10 1577
Hi,

I dont see where you added it to the form's controls.

Ken
------------------
"Rob" <rl*****@worldnet.att.net> wrote in message
news:u0**************@TK2MSFTNGP10.phx.gbl...
Question : I want to create a read only TextBox that does not
respond to any input from the keyboard, therefore I came up
with the following derived class :

Option Strict On

Imports System.Windows.Forms.TextBox

Public Class DerivedTextBox
Inherits TextBox

Protected Overridable Sub KeyEventHandler( _
ByVal sender As Object, _
ByVal e As KeyEventHandler)

End Sub

End Class
I then place this TextBox on my Form1 using the following :

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
Me.TextBox1.Show()
'
'TextBox1
'
Me.TextBox1.AutoSize = False
Me.TextBox1.Location = New System.Drawing.Point(8, 8)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.ReadOnly = True
Me.TextBox1.Size = New System.Drawing.Size(230, 150)
Me.TextBox1.TabIndex = 1
Me.TextBox1.TabStop = False
Me.TextBox1.Text = ""
Me.TextBox1.Visible = True
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents TextBox1 As DerivedTextBox

However the TextBox remains invisible. How can I get
TextBox1 to appear on Form1 ?
Mar 28 '06 #2
Rob
Your right ! ! ! , I needed to make the following addition :
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1, Me.Button1, Me.TextBox1})

Unfortunately, I'm still back to square one, my TextBox1 still
responds to keyboard events. Is there a way to rewrite the
Class DerivedTextBox to prevent keyboard response ?
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I dont see where you added it to the form's controls.

Ken
------------------
"Rob" <rl*****@worldnet.att.net> wrote in message
news:u0**************@TK2MSFTNGP10.phx.gbl...
Question : I want to create a read only TextBox that does not
respond to any input from the keyboard, therefore I came up
with the following derived class :

Option Strict On

Imports System.Windows.Forms.TextBox

Public Class DerivedTextBox
Inherits TextBox

Protected Overridable Sub KeyEventHandler( _
ByVal sender As Object, _
ByVal e As KeyEventHandler)

End Sub

End Class


I then place this TextBox on my Form1 using the following :

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
Me.TextBox1.Show()
'
'TextBox1
'
Me.TextBox1.AutoSize = False
Me.TextBox1.Location = New System.Drawing.Point(8, 8)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.ReadOnly = True
Me.TextBox1.Size = New System.Drawing.Size(230, 150)
Me.TextBox1.TabIndex = 1
Me.TextBox1.TabStop = False
Me.TextBox1.Text = ""
Me.TextBox1.Visible = True
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents TextBox1 As DerivedTextBox

However the TextBox remains invisible. How can I get
TextBox1 to appear on Form1 ?

Mar 28 '06 #3

"Rob" <rl*****@worldnet.att.net> wrote in message
news:u1**************@TK2MSFTNGP09.phx.gbl...
Your right ! ! ! , I needed to make the following addition : Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1,
Me.Button1, Me.TextBox1})
Unfortunately, I'm still back to square one, my TextBox1 still

responds to keyboard events. Is there a way to rewrite the
Class DerivedTextBox to prevent keyboard response ?

FWIW, I always try a label first for this. I'm assuming that won't work for
you?

Disabling shortcuts and making it readonly isn't enough?


Mar 28 '06 #4
Rob,

Why are you doing it this difficult. A label with a white background looks in my opinion the same.

Cor
"Rob" <rl*****@worldnet.att.net> schreef in bericht news:u1**************@TK2MSFTNGP09.phx.gbl...
Your right ! ! ! , I needed to make the following addition :
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1, Me.Button1, Me.TextBox1})

Unfortunately, I'm still back to square one, my TextBox1 still
responds to keyboard events. Is there a way to rewrite the
Class DerivedTextBox to prevent keyboard response ?
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I dont see where you added it to the form's controls.

Ken
------------------
"Rob" <rl*****@worldnet.att.net> wrote in message
news:u0**************@TK2MSFTNGP10.phx.gbl...
Question : I want to create a read only TextBox that does not
respond to any input from the keyboard, therefore I came up
with the following derived class :

Option Strict On

Imports System.Windows.Forms.TextBox

Public Class DerivedTextBox
Inherits TextBox

Protected Overridable Sub KeyEventHandler( _
ByVal sender As Object, _
ByVal e As KeyEventHandler)

End Sub

End Class


I then place this TextBox on my Form1 using the following :

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
Me.TextBox1.Show()
'
'TextBox1
'
Me.TextBox1.AutoSize = False
Me.TextBox1.Location = New System.Drawing.Point(8, 8)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.ReadOnly = True
Me.TextBox1.Size = New System.Drawing.Size(230, 150)
Me.TextBox1.TabIndex = 1
Me.TextBox1.TabStop = False
Me.TextBox1.Text = ""
Me.TextBox1.Visible = True
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents TextBox1 As DerivedTextBox

However the TextBox remains invisible. How can I get
TextBox1 to appear on Form1 ?

Mar 28 '06 #5
Hi Rob,

If you simply must use a TextBox, contrary to the wise suggestions of
Cor and Homer (who suggested using a label), you still don't have to
create a Derived class. Creating a derived textbox seems too much
effort to incorporate such basic functionality.

You just need to add the *normal* textbox to your form, and you could
set it's ReadOnly property to True. To make it even more
*unresponsive*, simply handle the Keypress and KeyDown events, and
within each set "e.Handled = True", where e is specific type of
EventArgs for each of the mentioned events.

Regards,

Cerebrus.

Mar 28 '06 #6
Well, I can understand that you would want to make this dependent on a
property, to simulate the 'Locked' state we used to have in VB6. That
allowed the control to take focus, and to navigate inside the textbox with
the arrow keys, but did not allow the user to make any changes.
I am looking myself for such a 'state' too, so I can set a property
dependent on the users' rights. Such a state would be ideal for users who
only have 'Read' rights.
Currently I use the ReadOnly property for this, but that is so ugly. I looks
like the control is disabled.

Martin
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:u8**************@tk2msftngp13.phx.gbl...
Rob,

Why are you doing it this difficult. A label with a white background looks
in my opinion the same.

Cor
"Rob" <rl*****@worldnet.att.net> schreef in bericht
news:u1**************@TK2MSFTNGP09.phx.gbl...
Your right ! ! ! , I needed to make the following addition :
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1,
Me.Button1, Me.TextBox1})

Unfortunately, I'm still back to square one, my TextBox1 still
responds to keyboard events. Is there a way to rewrite the
Class DerivedTextBox to prevent keyboard response ?
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I dont see where you added it to the form's controls.

Ken
------------------
"Rob" <rl*****@worldnet.att.net> wrote in message
news:u0**************@TK2MSFTNGP10.phx.gbl...
Question : I want to create a read only TextBox that does not
respond to any input from the keyboard, therefore I came up
with the following derived class :

Option Strict On

Imports System.Windows.Forms.TextBox

Public Class DerivedTextBox
Inherits TextBox

Protected Overridable Sub KeyEventHandler( _
ByVal sender As Object, _
ByVal e As KeyEventHandler)

End Sub

End Class
I then place this TextBox on my Form1 using the following :

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
Me.TextBox1.Show()
'
'TextBox1
'
Me.TextBox1.AutoSize = False
Me.TextBox1.Location = New System.Drawing.Point(8, 8)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.ReadOnly = True
Me.TextBox1.Size = New System.Drawing.Size(230, 150)
Me.TextBox1.TabIndex = 1
Me.TextBox1.TabStop = False
Me.TextBox1.Text = ""
Me.TextBox1.Visible = True
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents TextBox1 As DerivedTextBox

However the TextBox remains invisible. How can I get
TextBox1 to appear on Form1 ?


Mar 28 '06 #7
Hi,

Martin wrote :
Currently I use the ReadOnly property for this, but that is so ugly. I looks
like the control is disabled.


Change the backcolor of the textbox back to normal, after you set it's
ReadOnly property to True. The normal behaviour is meant so that the
user gets a *visual* indication of the Readonly status. Else, users
would definitely try to type in the control a few times before
realizing that input is disabled, unless you give some other
indication.

Regards,

Cerebrus.

Mar 28 '06 #8
Yup, that does the trick, so I will override the Readonly property in my
subclass to keep the original background color. That would also be the way
to go for Rob I think.

Thanks for your contribution

Martin

"Cerebrus" <zo*****@sify.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
Hi,

Martin wrote :
Currently I use the ReadOnly property for this, but that is so ugly. I
looks
like the control is disabled.


Change the backcolor of the textbox back to normal, after you set it's
ReadOnly property to True. The normal behaviour is meant so that the
user gets a *visual* indication of the Readonly status. Else, users
would definitely try to type in the control a few times before
realizing that input is disabled, unless you give some other
indication.

Regards,

Cerebrus.

Mar 28 '06 #9
Hi,

In the keypress event you need e.handled=true

Ken
---------------
"Rob" <rl*****@worldnet.att.net> wrote in message
news:u1**************@TK2MSFTNGP09.phx.gbl...
Your right ! ! ! , I needed to make the following addition :
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1,
Me.Button1, Me.TextBox1})

Unfortunately, I'm still back to square one, my TextBox1 still
responds to keyboard events. Is there a way to rewrite the
Class DerivedTextBox to prevent keyboard response ?
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I dont see where you added it to the form's controls.

Ken
------------------
"Rob" <rl*****@worldnet.att.net> wrote in message
news:u0**************@TK2MSFTNGP10.phx.gbl...
Question : I want to create a read only TextBox that does not
respond to any input from the keyboard, therefore I came up
with the following derived class :

Option Strict On

Imports System.Windows.Forms.TextBox

Public Class DerivedTextBox
Inherits TextBox

Protected Overridable Sub KeyEventHandler( _
ByVal sender As Object, _
ByVal e As KeyEventHandler)

End Sub

End Class
I then place this TextBox on my Form1 using the following :

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
Me.TextBox1.Show()
'
'TextBox1
'
Me.TextBox1.AutoSize = False
Me.TextBox1.Location = New System.Drawing.Point(8, 8)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.ReadOnly = True
Me.TextBox1.Size = New System.Drawing.Size(230, 150)
Me.TextBox1.TabIndex = 1
Me.TextBox1.TabStop = False
Me.TextBox1.Text = ""
Me.TextBox1.Visible = True
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents TextBox1 As DerivedTextBox

However the TextBox remains invisible. How can I get
TextBox1 to appear on Form1 ?


Mar 28 '06 #10
That makes me wonder... Why didn't MS put a ReadOnly property on other
controls, such as the combobox, checkbox and radiobutton? Now everybody who
needs that (and/or used it in VB6) has to re-invent the wheel all over
again.

"Cerebrus" <zo*****@sify.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
Hi,

Martin wrote :
Currently I use the ReadOnly property for this, but that is so ugly. I
looks
like the control is disabled.


Change the backcolor of the textbox back to normal, after you set it's
ReadOnly property to True. The normal behaviour is meant so that the
user gets a *visual* indication of the Readonly status. Else, users
would definitely try to type in the control a few times before
realizing that input is disabled, unless you give some other
indication.

Regards,

Cerebrus.

Mar 28 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2078
by: John B | last post by:
Hello I want to create a set of controls that have some common methods and properties. I was thinking that I should subclass the UserControl class and add these common features there and then...
1
1165
by: seven | last post by:
I'm playing with page inheritence but I am currently stumped by postback, on a page derived from a base class. In my base page/class I have defined an HTMLForm object. It is instantiated and...
7
1458
by: Graham Blandford | last post by:
OK, having answered my questions in a previous feed about pulling my derived class into the IDE.... Here's a new problem that I'm hoping can be fixed and isn't a .NET bug.... I have created an...
7
1500
by: Dennis | last post by:
I have a control that inherits from the Panel Class. To this, I added a label which I want to use as a caption in my derived control. However, I can't get the label to show up in the panel. I...
1
1180
by: Sosh | last post by:
Hi, I'm pulling my hair out trying to work this out. Pehaps I am missunderstanding something - hopefully someone can shed some light on this: 1) I have a class library that contains a bunch...
0
961
by: nave11 | last post by:
How to add Context menu to a class derived from System.Windows.Forms.Label ? This label will be dragged on a designer surface on runtime. For example, to add a context menu with "Copy" and "Paste"...
0
1881
by: =?Utf-8?B?Q29yZXlNY0s=?= | last post by:
I'm working on a TextBox control (in C# using .NET 2.0) that allows fields (like MS Office's mail merge feature). I want the editor to treat the field as though it was a single character. The user...
5
5060
by: hufaunder | last post by:
I would like to create a specialized TextBox (WPF) that for instance only accept integers/decimals/currency/etc. Since I want it to behave like a TextBox but don't want to write one myself I would...
1
2213
by: =?Utf-8?B?Q2hyaXN0aWFuIFdlaW5lcnQ=?= | last post by:
Hello, I currently fight with a problem during the derivative of WinForm controls. In Visual Studio I created a new User Control. This control is derived from the DataGridView of the...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
7066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
435
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.