-
Aug 1st, 2008, 03:51 AM
#1
Thread Starter
Addicted Member
[RESOLVED] How to make textbox 'gray-out'?
How to make a text box, not able to let users write anything on it?
Where the box will appears to be grey-out...?
-
Aug 1st, 2008, 03:59 AM
#2
Re: How to make textbox 'gray-out'?
-
Aug 1st, 2008, 04:06 AM
#3
Thread Starter
Addicted Member
Re: How to make textbox 'gray-out'?
hmm. but mine still enables user to write it in. Not able to gray-out.
I'm not sure if my other codings affect it too but I just post it in here
vb Code:
Private Sub cboCost_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCost.SelectedIndexChanged
cboCost.SelectedIndex = 0
cboCost.Enabled = False
End Sub
Private Sub cboSource_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboSource.SelectedIndexChanged
If cboSource.Enabled = False Then
cboSource.SelectedIndex = 0
ElseIf cboSource.Enabled = True Then
cboSource.Enabled = chkboxCost.Checked
End If
End Sub
Private Sub chkboxCost_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkboxCost.CheckedChanged
If cboSource.Enabled = False Then
cboSource.Enabled = chkboxCost.Checked
End If
End Sub
Private Sub txtCMaterial_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCMaterial.TextChanged
txtCMaterial.Enabled = False
End Sub
-
Aug 1st, 2008, 07:34 AM
#4
Re: How to make textbox 'gray-out'?
Originally Posted by melvados
hmm. but mine still enables user to write it in. Not able to gray-out.
I'm not sure if my other codings affect it too but I just post it in here
vb Code:
Private Sub cboCost_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCost.SelectedIndexChanged
cboCost.SelectedIndex = 0
cboCost.Enabled = False
End Sub
Private Sub cboSource_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboSource.SelectedIndexChanged
If cboSource.Enabled = False Then
cboSource.SelectedIndex = 0
ElseIf cboSource.Enabled = True Then
cboSource.Enabled = chkboxCost.Checked
End If
End Sub
Private Sub chkboxCost_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkboxCost.CheckedChanged
If cboSource.Enabled = False Then
cboSource.Enabled = chkboxCost.Checked
End If
End Sub
Private Sub txtCMaterial_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCMaterial.TextChanged
txtCMaterial.Enabled = False
End Sub
All I'm going to say is, good god this is an app maintenance nightmare right here
-
Aug 1st, 2008, 04:31 AM
#5
Re: How to make textbox 'gray-out'?
I assume its the txtCMaterial control that you are trying to grey out? If so, why are you doing it in the TextChanged event? That event will fire when someone begins to type into the box... I am guessing you want it greyed out before then. If thats the case then just do it in the form load event or something like that, so that the box is already greyed out before the user can attempt to type in it. You could even do it in the designer (assuming it wants to be greyed out for the lifetime of your app)
-
Aug 1st, 2008, 08:26 AM
#6
Re: How to make textbox 'gray-out'?
Originally Posted by melvados
How to make a text box, not able to let users write anything on it?
Where the box will appears to be grey-out...?
If you want to disable a textbox (or any other control for that matter) do it on the property page.
-
Aug 1st, 2008, 08:27 AM
#7
Junior Member
Re: How to make textbox 'gray-out'?
-
Aug 1st, 2008, 08:41 AM
#8
Re: How to make textbox 'gray-out'?
Originally Posted by endri12
textbox.readonly= true
that wont "grey-out" the control, which is what the OP asked for
-
Aug 1st, 2008, 11:00 AM
#9
Junior Member
Re: How to make textbox 'gray-out'?
Originally Posted by chris128
that wont "grey-out" the control, which is what the OP asked for
what are you talking about?
the op asked to make textbox not able to write anything and grayed out , doesn't readonly property do that?
-
Aug 1st, 2008, 11:45 AM
#10
Re: How to make textbox 'gray-out'?
Originally Posted by endri12
what are you talking about?
the op asked to make textbox not able to write anything and grayed out , doesn't readonly property do that?
Yes it does, if he wants it grayed out he can set the readonly property to True then change the backcolor to gray.
-
Aug 1st, 2008, 12:25 PM
#11
Re: How to make textbox 'gray-out'?
Originally Posted by JuggaloBrotha
Yes it does, if he wants it grayed out he can set the readonly property to True then change the backcolor to gray.
Yeah but just setting Enabled to false does the exact same thing but in one line... I dont know if your just messing around or if your being serious but its blatantly obvious (to me anyway) that the OP was just refering to how controls look when they are not enabled when he said greyed out. Why change ReadOnly and the background colour when you can just type TextBox.Enabled = False :S
-
Aug 1st, 2008, 12:30 PM
#12
Re: How to make textbox 'gray-out'?
Actually, there's a significant difference.... if the control is not enabled, it cannot receive focus.... the text cant's be highlighted (I think) and you cannot scroll the text box. Why would that matter? If I want a text box that has text in it that is larger than can be displayed, or may be needed else where (think copy-paste) .... I may not want the user to edit the info so, but I want then to be able to see the data, setting ReadOnly gives me that... but it doesn't give any indication that it is readonly.... so I have to provide some other visual cue that the data can't be edited.... enter the grey out.
-tg
-
Aug 1st, 2008, 12:52 PM
#13
Re: How to make textbox 'gray-out'?
Originally Posted by techgnome
Actually, there's a significant difference.... if the control is not enabled, it cannot receive focus.... the text cant's be highlighted (I think) and you cannot scroll the text box. Why would that matter? If I want a text box that has text in it that is larger than can be displayed, or may be needed else where (think copy-paste) .... I may not want the user to edit the info so, but I want then to be able to see the data, setting ReadOnly gives me that... but it doesn't give any indication that it is readonly.... so I have to provide some other visual cue that the data can't be edited.... enter the grey out.
-tg
I appreciate that but the OP didnt mention anything like that, he just said he wanted to grey-out the box which to me always means setting textbox.Enabled to false.
Also, the OP posted some code that he was using to set Enabled to False and said that it did not work so saying that he should try setting ReadOnly to False is not going to work either... because Enabled = False is only not working because he is using it in the wrong place or something similar.
Anyway I'm going to shut up now because the OP has probably forgotten about this thread by now or has fixed it himself.
-
Aug 1st, 2008, 12:44 PM
#14
Addicted Member
Re: How to make textbox 'gray-out'?
I think you're looking for something like this:
Code:
TextBox1.ReadOnly = True
========================================
Sorry, my bad.
Last edited by Louix; Aug 1st, 2008 at 12:47 PM.
-
Aug 1st, 2008, 01:00 PM
#15
Re: How to make textbox 'gray-out'?
1) My comment had more to do with the "" comment of yours.... I was simply noting that SOMETIMES there's a reason to use ReadOnly AND change the background.
2) The OP is after more than jsut greying out the text -> "not able to let users write anything on it?" Therefore it is not jsut a visual problem, but also a functional issue. In this case, If the OP has no interest in copying teh text, or scrolling or highlighting any portion of the text, then .Enabled *should* be the appropriate solution. I think it didn't work for the OP because of WHERE he was attempting to set the enabled property - in the Textchanged event - which doesn't fire until AFTER the user has tried to edit the text. Needs to be done before that.
-tg
-
Aug 1st, 2008, 01:02 PM
#16
Re: How to make textbox 'gray-out'?
No, he said the textbox would be greyed out, not just the text. Otherwise I would not of suggested it and yeah I already mentioned about the fact that he was doing it in the wrong place
-
Aug 1st, 2008, 02:23 PM
#17
Re: How to make textbox 'gray-out'?
Just goes to show... ask 6 developers a question, you'll get 12 different answers... it's all in the interpretation.... You read it one way, I another....
Here's another wrench, why use a text box at all? Labels.... labels work jsut as well too...
-tg
-
Aug 1st, 2008, 07:07 PM
#18
Re: How to make textbox 'gray-out'?
setting textboxes as readonly automatically changes the backcolor to systemcolors.control
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 2nd, 2008, 05:23 AM
#19
Re: How to make textbox 'gray-out'?
Originally Posted by .paul.
setting textboxes as readonly automatically changes the backcolor to systemcolors.control
so it does! never knew that
-
Oct 1st, 2014, 12:47 PM
#20
New Member
Re: [RESOLVED] How to make textbox 'gray-out'?
Although this marked resolved, user should also look to whether the textbox is locked. If it isn't, setting to enabled = false won't turn grey.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|