473,657 Members | 2,504 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.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call
Me.TextBox1.Sho w()
'
'TextBox1
'
Me.TextBox1.Aut oSize = False
Me.TextBox1.Loc ation = New System.Drawing. Point(8, 8)
Me.TextBox1.Mul tiline = True
Me.TextBox1.Nam e = "TextBox1"
Me.TextBox1.Rea dOnly = True
Me.TextBox1.Siz e = New System.Drawing. Size(230, 150)
Me.TextBox1.Tab Index = 1
Me.TextBox1.Tab Stop = False
Me.TextBox1.Tex t = ""
Me.TextBox1.Vis ible = 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.Disp ose()
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 1586
Hi,

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

Ken
------------------
"Rob" <rl*****@worldn et.att.net> wrote in message
news:u0******** ******@TK2MSFTN GP10.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.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call
Me.TextBox1.Sho w()
'
'TextBox1
'
Me.TextBox1.Aut oSize = False
Me.TextBox1.Loc ation = New System.Drawing. Point(8, 8)
Me.TextBox1.Mul tiline = True
Me.TextBox1.Nam e = "TextBox1"
Me.TextBox1.Rea dOnly = True
Me.TextBox1.Siz e = New System.Drawing. Size(230, 150)
Me.TextBox1.Tab Index = 1
Me.TextBox1.Tab Stop = False
Me.TextBox1.Tex t = ""
Me.TextBox1.Vis ible = 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.Disp ose()
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.Add Range(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***@bellsout h.net> wrote in message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi,

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

Ken
------------------
"Rob" <rl*****@worldn et.att.net> wrote in message
news:u0******** ******@TK2MSFTN GP10.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.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call
Me.TextBox1.Sho w()
'
'TextBox1
'
Me.TextBox1.Aut oSize = False
Me.TextBox1.Loc ation = New System.Drawing. Point(8, 8)
Me.TextBox1.Mul tiline = True
Me.TextBox1.Nam e = "TextBox1"
Me.TextBox1.Rea dOnly = True
Me.TextBox1.Siz e = New System.Drawing. Size(230, 150)
Me.TextBox1.Tab Index = 1
Me.TextBox1.Tab Stop = False
Me.TextBox1.Tex t = ""
Me.TextBox1.Vis ible = 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.Disp ose()
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*****@worldn et.att.net> wrote in message
news:u1******** ******@TK2MSFTN GP09.phx.gbl...
Your right ! ! ! , I needed to make the following addition : Me.Controls.Add Range(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*****@worldn et.att.net> schreef in bericht news:u1******** ******@TK2MSFTN GP09.phx.gbl...
Your right ! ! ! , I needed to make the following addition :
Me.Controls.Add Range(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***@bellsout h.net> wrote in message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi,

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

Ken
------------------
"Rob" <rl*****@worldn et.att.net> wrote in message
news:u0******** ******@TK2MSFTN GP10.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.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call
Me.TextBox1.Sho w()
'
'TextBox1
'
Me.TextBox1.Aut oSize = False
Me.TextBox1.Loc ation = New System.Drawing. Point(8, 8)
Me.TextBox1.Mul tiline = True
Me.TextBox1.Nam e = "TextBox1"
Me.TextBox1.Rea dOnly = True
Me.TextBox1.Siz e = New System.Drawing. Size(230, 150)
Me.TextBox1.Tab Index = 1
Me.TextBox1.Tab Stop = False
Me.TextBox1.Tex t = ""
Me.TextBox1.Vis ible = 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.Disp ose()
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******** ******@tk2msftn gp13.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*****@worldn et.att.net> schreef in bericht
news:u1******** ******@TK2MSFTN GP09.phx.gbl...
Your right ! ! ! , I needed to make the following addition :
Me.Controls.Add Range(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***@bellsout h.net> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi,

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

Ken
------------------
"Rob" <rl*****@worldn et.att.net> wrote in message
news:u0******** ******@TK2MSFTN GP10.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.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call
Me.TextBox1.Sho w()
'
'TextBox1
'
Me.TextBox1.Aut oSize = False
Me.TextBox1.Loc ation = New System.Drawing. Point(8, 8)
Me.TextBox1.Mul tiline = True
Me.TextBox1.Nam e = "TextBox1"
Me.TextBox1.Rea dOnly = True
Me.TextBox1.Siz e = New System.Drawing. Size(230, 150)
Me.TextBox1.Tab Index = 1
Me.TextBox1.Tab Stop = False
Me.TextBox1.Tex t = ""
Me.TextBox1.Vis ible = 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.Disp ose()
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.c om> wrote in message
news:11******** **************@ z34g2000cwc.goo glegroups.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*****@worldn et.att.net> wrote in message
news:u1******** ******@TK2MSFTN GP09.phx.gbl...
Your right ! ! ! , I needed to make the following addition :
Me.Controls.Add Range(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***@bellsout h.net> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi,

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

Ken
------------------
"Rob" <rl*****@worldn et.att.net> wrote in message
news:u0******** ******@TK2MSFTN GP10.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.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call
Me.TextBox1.Sho w()
'
'TextBox1
'
Me.TextBox1.Aut oSize = False
Me.TextBox1.Loc ation = New System.Drawing. Point(8, 8)
Me.TextBox1.Mul tiline = True
Me.TextBox1.Nam e = "TextBox1"
Me.TextBox1.Rea dOnly = True
Me.TextBox1.Siz e = New System.Drawing. Size(230, 150)
Me.TextBox1.Tab Index = 1
Me.TextBox1.Tab Stop = False
Me.TextBox1.Tex t = ""
Me.TextBox1.Vis ible = 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.Disp ose()
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

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

Similar topics

2
2088
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 base all my custom controls on this new MyUserControl Class. Is this the way to go? The MyUserControl would not actually have any UI component and should be abstract I think. Does this mena that I should not create the control by just selecting...
1
1171
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 added to the base page's control collection during the Init event of the base page. I expose this form object to any given derived page through a public property. And this works, more or less; from the derived page, I can instantiate textboxes,...
7
1465
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 inherited class based on the textbox... which, all I am doing is allowing a forecolor to be set when .enabled is set to true. it works nicely, EXCEPT that when I click into the box, the font (set as default MS Sans 8.25pt) does not appear to be...
7
1510
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 tried a text box and it works fine. I've tried everything on the label from visible=True, BringToFront, etc. but I can't get it to show up. Is this a bug in VS or can one just not do this? -- Dennis in Houston
1
1184
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 of custom web controls. Two of these controls are derived from the TextBox control, and overide the onLoad method in order to add some client side attributes, eg: namespace SomeControls{
0
983
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" to a Label or TextBox? I have tried adding the context menu code in designer , and i can get the context menu at design time , but cannot see that at runtime. if any other way its possible , please let me know.
0
1886
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 shouldn't be able to delete part of the field or select only part of the field. For example, a line might look like: «Image» shot on «Date» at «Resolution» where «Image» «Date» «Resolution» are all fields. My control inherits from...
5
5066
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 like to create a user control. The idea was to derive a user control (Add Items...UserControl) from a TextBox but Visual Studio does not let me define a base class. I could go and change it by hand but I guess there is a reason why MS didn't...
1
2219
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 System.Windows.Forms namespace. I want to use this control as a template for futher controls. Within this control i want to set some property values to be pre-defined for further derived controls. My base class looks like this:
0
8421
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8518
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7354
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5643
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.