Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted
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?

-Sean
Posted

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

Posted
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?
Posted
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.
"Nobody knows what I do until I stop doing it."

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...