grip003 Posted January 14, 2005 Posted January 14, 2005 Hey everyone. I have written a form in which there are a lot of textboxes that store information. However, I don't allow changes unless the user presses Edit. This is done by setting the ReadOnly property to true until the user presses Edit, which sets it to false. However, I need the ability to change the forecolor of the textboxes to be something other than black while readonly is set to true. Is there any way to do this? Right now, everything looks black until I hit Edit, in which all the textboxes take on the forecolor that I assigned them. If the enabled property can be used somehow, that would also work for my application. Quote
coldfusion244 Posted January 14, 2005 Posted January 14, 2005 Hey everyone. I have written a form in which there are a lot of textboxes that store information. However, I don't allow changes unless the user presses Edit. This is done by setting the ReadOnly property to true until the user presses Edit, which sets it to false. However, I need the ability to change the forecolor of the textboxes to be something other than black while readonly is set to true. Is there any way to do this? Right now, everything looks black until I hit Edit, in which all the textboxes take on the forecolor that I assigned them. If the enabled property can be used somehow, that would also work for my application. If I am understanding you correctly, when your application starts your textbox's forecolor is black, and you want that a different color? Quote -Sean
IngisKahn Posted January 14, 2005 Posted January 14, 2005 Ya, not to sure what you mean. You can set the colors however you want with ForeColor and BackColor. (using SystemColors is the best bet) Quote "Who is John Galt?"
sgt_pinky Posted January 17, 2005 Posted January 17, 2005 When the ReadOnly or Enabled properties are set to true, you cannot change the display color. One thing you can do though is to handle the keypresses. Create a private Boolean called bEditMode that you set to 'True' when in edit mode, and 'False' when not in edit mode. Then use following code. At the end of the Sub declaration you see "Handles TB1.KeyPress". Add handles for all your textboxes here, eg: "Handles TB1.KeyPress, TB2.KeyPress, ... Private Sub TB1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TB1.KeyPress If Not bEditMode Then e.Handled = True End Sub Quote
grip003 Posted January 20, 2005 Author Posted January 20, 2005 Hey everyone, thanks for the replies. From what I have been reading, the ForeColor can not be changed when the ReadOnly property is set to true. I need to keep the text boxes as ReadOnly, but I need a way to show the user that something is different. My first idea was ForeColor, but maybe there is something else I can use, maybe something with the BorderStyle? Quote
Rick_Fla Posted January 20, 2005 Posted January 20, 2005 You can change the backcolor of the textbox, and yes, it can be changed in readonly status. That would be the only way I can think of right off the bat without using the keypress method suggested earlier. Quote "Nobody knows what I do until I stop doing it."
donnacha Posted January 21, 2005 Posted January 21, 2005 Have you tried setting the enable flag instead of the readonly, that might allow you to change the color. Quote Hamlet
grip003 Posted January 21, 2005 Author Posted January 21, 2005 It looks like the BackColor property will work. It isn't exactly what I wanted, but I think it should be okay. Thanks again for all the help. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.