read-only vs locked textbox

  • Thread starter Thread starter dennist
  • Start date Start date
D

dennist

the read only property is no substitute for the locked
property of a textbox in vb6. The read only property
allows the text to be changed or wiped out
programmatically. You simply can't change it by clicking
in the textbox and start typing.

Is there any way the this grand new world of vb.net of
doing something so simple and important as locking the
text in a textbox?

dennist
 
You could easily create a control that looked like a text box but with a
read-only Text property.
You'd have to set the text in the constructor or something though because
you couldn't do it at design time.

Why not just use a label?

--
Bob Powell [MVP]
C#, System.Drawing

ANNOUNCING: Well Formed.
The monthy electronic magazine for
Windows Forms and GDI+ engineers
http://www.bobpowell.net/wellformed.htm

Check out the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
 
Bob,

thanks for your reply, but....

I'm not going to design my own control for a locked
property. That's ridiculous, as far as I'm concerned.
Microsoft should be providing it. Period.

Second, a label control won't do. I need it as a textbox
at first, at which time it can be edited. Only later
when everything is in order with other controls do I want
it locked. Changing it into a label control at that time
is another preposterous exercise that only a programming
designer could love. Bring back RAD to VB!!!

Dennis
 
Hi Dennis,
It seems that the implementation of TextBox.ReadOnly property will
grey the color when you set it to false.
but It's not always set the color, so you may play a trick on it,just like
void ReadOnlyBox()
{
Color tmp = textBox1.BackColor;
textBox1.ReadOnly = true;
//in fact , you only need reset the BackColor when the ReadOnly = true
firstly called.
textBox1.BackColor = tmp;
}
void ReadWriteTextBox()
{
textBox1.ReadOnly = false;
}
this code works on my system, Please tell me if you meet some problems in
using it.
Thanks!

Kind regards,

Ying-Shen Yu [MS]
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2001 Microsoft Corporation. All rights
reserved.
--------------------
| Content-Class: urn:content-classes:message
| From: "dennist" <[email protected]>
| Sender: "dennist" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: read-only vs locked textbox
| Date: Mon, 8 Sep 2003 01:32:56 -0700
| Lines: 57
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcN1483m49hU1lm2SvmwwRa0rXgJuA==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:51847
| NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| Bob,
|
| thanks for your reply, but....
|
| I'm not going to design my own control for a locked
| property. That's ridiculous, as far as I'm concerned.
| Microsoft should be providing it. Period.
|
| Second, a label control won't do. I need it as a textbox
| at first, at which time it can be edited. Only later
| when everything is in order with other controls do I want
| it locked. Changing it into a label control at that time
| is another preposterous exercise that only a programming
| designer could love. Bring back RAD to VB!!!
|
| Dennis
| >-----Original Message-----
| >You could easily create a control that looked like a
| text box but with a
| >read-only Text property.
| >You'd have to set the text in the constructor or
| something though because
| >you couldn't do it at design time.
| >
| >Why not just use a label?
| >
| >--
| >Bob Powell [MVP]
| >C#, System.Drawing
| >
| >ANNOUNCING: Well Formed.
| >The monthy electronic magazine for
| >Windows Forms and GDI+ engineers
| >http://www.bobpowell.net/wellformed.htm
| >
| >Check out the GDI+ FAQ
| >http://www.bobpowell.net/gdiplus_faq.htm
| >
| >
| >| >> the read only property is no substitute for the locked
| >> property of a textbox in vb6. The read only property
| >> allows the text to be changed or wiped out
| >> programmatically. You simply can't change it by
| clicking
| >> in the textbox and start typing.
| >>
| >> Is there any way the this grand new world of vb.net of
| >> doing something so simple and important as locking the
| >> text in a textbox?
| >>
| >> dennist
| >
| >
| >.
| >
|
 
Hi Dennist,
You haven't update your post for some days,
How about your problem now?
Please let me know if you still have problem on this issue, thanks!

Kind regards,

Ying-Shen Yu [MS]
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2001 Microsoft Corporation. All rights
reserved.
--------------------
| Content-Class: urn:content-classes:message
| From: "dennist" <[email protected]>
| Sender: "dennist" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: read-only vs locked textbox
| Date: Mon, 8 Sep 2003 01:32:56 -0700
| Lines: 57
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcN1483m49hU1lm2SvmwwRa0rXgJuA==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:51847
| NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| Bob,
|
| thanks for your reply, but....
|
| I'm not going to design my own control for a locked
| property. That's ridiculous, as far as I'm concerned.
| Microsoft should be providing it. Period.
|
| Second, a label control won't do. I need it as a textbox
| at first, at which time it can be edited. Only later
| when everything is in order with other controls do I want
| it locked. Changing it into a label control at that time
| is another preposterous exercise that only a programming
| designer could love. Bring back RAD to VB!!!
|
| Dennis
| >-----Original Message-----
| >You could easily create a control that looked like a
| text box but with a
| >read-only Text property.
| >You'd have to set the text in the constructor or
| something though because
| >you couldn't do it at design time.
| >
| >Why not just use a label?
| >
| >--
| >Bob Powell [MVP]
| >C#, System.Drawing
| >
| >ANNOUNCING: Well Formed.
| >The monthy electronic magazine for
| >Windows Forms and GDI+ engineers
| >http://www.bobpowell.net/wellformed.htm
| >
| >Check out the GDI+ FAQ
| >http://www.bobpowell.net/gdiplus_faq.htm
| >
| >
| >| >> the read only property is no substitute for the locked
| >> property of a textbox in vb6. The read only property
| >> allows the text to be changed or wiped out
| >> programmatically. You simply can't change it by
| clicking
| >> in the textbox and start typing.
| >>
| >> Is there any way the this grand new world of vb.net of
| >> doing something so simple and important as locking the
| >> text in a textbox?
| >>
| >> dennist
| >
| >
| >.
| >
|
 
Thanks everybody,

I've gone as far on locked vs read-only as I'm willing to. I'll just
have to make sure nobody can change the text programmatically, and that
the text is backed up and checked at necessary points.

dennist
 
Hi Dennis,
I'm sorry for spending you so much time. You said that the Lock
property in VB6 will prevent modifying the control's data even in a
programmatic way? However, as far as I know, VB6 doesn't provide this
feature, if you have some sample code that show it supports this feature.
Please send it to me, I'll research on it to see if we can do equivalent
things in
VB.NET.
And I think the code I provided in previous post has simulated the Lock
Property behavior of TextBox in VB6. If you have any problem on this
workaround , please let me know.
If you do want to prevent modifying the Text Property, maybe you need
create you own control by deriving from the TextBox and override the Text
Property.(define getter method only).

Thanks again !

Kind regards,

Ying-Shen Yu [MS]
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2001 Microsoft Corporation. All rights
reserved.
--------------------
| From: dennis turner <[email protected]>
| References: <[email protected]>
| X-Newsreader: AspNNTP 1.50 (ActionJackson.com)
| Subject: Re: read-only vs locked textbox
| Mime-Version: 1.0
| Content-Type: text/plain; charset="us-ascii"
| Content-Transfer-Encoding: 7bit
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Date: Wed, 10 Sep 2003 03:46:53 -0700
| NNTP-Posting-Host: actionjackson133.dsl.frii.net 216.17.147.133
| Lines: 1
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:52030
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| Thanks everybody,
|
| I've gone as far on locked vs read-only as I'm willing to. I'll just
| have to make sure nobody can change the text programmatically, and that
| the text is backed up and checked at necessary points.
|
| dennist
|
|
|
|
| Don't just participate in USENET...get rewarded for it!
|
 
Ying-Shen Yu said:
I'm sorry for spending you so much time. You said that the Lock
property in VB6 will prevent modifying the control's data even in a
programmatic way? However, as far as I know, VB6 doesn't provide this
feature, if you have some sample code that show it supports this feature.
Please send it to me, I'll research on it to see if we can do equivalent
things in
VB.NET.


To echo Ying-Shen Yu comments, I wasn't aware that the Locked property
worked in this way in VB6. AFAIK it just sets the ES_READONLY style on the
TextBox; it doesn't prevent changes via the Text property.

Using the following code I always see " Changed." appended, but on alternate
clicks I can't edit the text manually.

Private Sub Form_Click()
Text1.Locked = Not Text1.Locked
Text1.Text = Text1.Text & " Changed."
End Sub

If you want this behaviour in VB.NET then you should be able to derive a
control from TextBox that overrides the Text property. Something like this
(untested) might do the trick:

Public Class LockedTextBox
Inherits TextBox

Protected Overrides Property Text() As String
Get
Return MyBase.Text
End Get
Set(value As String)
If Not ReadOnly Then MyBase.Text = value
End Set
End Sub

End Class
 
Hey, this override looks doable, even for a dolt like me!!!

I'll give it a try.

dennist
 
Hi Kevin,
Thanks for your detail explanation!


Best regards,

Ying-Shen Yu [MS]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Kevin Westhead" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: read-only vs locked textbox
| Date: Wed, 10 Sep 2003 14:43:28 +0100
| Lines: 45
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <e#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| NNTP-Posting-Host: host5.i2.co.uk 193.129.24.5
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:52041
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| | > I'm sorry for spending you so much time. You said that the Lock
| > property in VB6 will prevent modifying the control's data even in a
| > programmatic way? However, as far as I know, VB6 doesn't provide this
| > feature, if you have some sample code that show it supports this
feature.
| > Please send it to me, I'll research on it to see if we can do equivalent
| > things in
| > VB.NET.
|
|
| To echo Ying-Shen Yu comments, I wasn't aware that the Locked property
| worked in this way in VB6. AFAIK it just sets the ES_READONLY style on the
| TextBox; it doesn't prevent changes via the Text property.
|
| Using the following code I always see " Changed." appended, but on
alternate
| clicks I can't edit the text manually.
|
| Private Sub Form_Click()
| Text1.Locked = Not Text1.Locked
| Text1.Text = Text1.Text & " Changed."
| End Sub
|
| If you want this behaviour in VB.NET then you should be able to derive a
| control from TextBox that overrides the Text property. Something like this
| (untested) might do the trick:
|
| Public Class LockedTextBox
| Inherits TextBox
|
| Protected Overrides Property Text() As String
| Get
| Return MyBase.Text
| End Get
| Set(value As String)
| If Not ReadOnly Then MyBase.Text = value
| End Set
| End Sub
|
| End Class
|
| --
| Kevin Westhead
|
|
|
 
Back
Top