Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make TextBox look and behave like a label 3

Status
Not open for further replies.

HughLerwill

Programmer
Nov 22, 2004
1,818
GB
Dear all,

Can I make a text box behave like it is disabled without it dimming the text inside it?

Locking is not an option because I would like to prevent the control recieving focus.

TIA Hugh,
 





Hi,

What about "replacing" it with something else, a lable, until it is enabled?

Skip,

[glasses] When a group touring the Crest Toothpaste factory got caught in a large cooler, headlines read...
Tooth Company Freeze a Crowd! and
Many are Cold, but Few are Frozen![tongue]
 
Skip,

Yes I'd considered that but;

The main reason I'd like to do this is because I have a quite complex form which was originally designed and may still be needed to enter/ edit/ display records from a file. I would now like the form to appear the same but for it to be for read/ review only. All is well when the Textboxes are dis-Enabled except for the dimmed text.
 
What I do is set the backcolor to grey and set the TabStop property to False, and of course setting the Locked property to True.

Setting the TabStop helps some, as the only way now for it to receive focus is in code, or when the user clicks on the control.

For that you could set the focus to another control using the GotFocus event, when this control receives focus and is Locked. You could also use SendKeys "{TAB}" in the GotFocus event which will cause the next control in the Tab order with it's TabStop set to True to get focus.
 

Of course, if another control doesn't really need to receive the focus if the user clicks on the locked control, you could just destroy the caret using the SendMessage API function and send the WM_KILLFOCUS message (in addition to locking the control and not allowing a TabStop).
The control is still actually the active control, but the caret is not blinking and the user cannot enter data.

Another, maybe easier method, and what seems to work, is to use the Enabled property in conjunction with the Locked property and the Got/Lost focus events.
Code:
Private Sub TextBox1_GotFocus(Index As Integer)
If txtBX(Index).Locked = True Then
    txtBX(Index).Enabled = False
End If
End Sub

Private Sub TextBox1_LostFocus(Index As Integer)
If txtBX(Index).Locked = True Then
    txtBX(Index).Enabled = True
End If
End Sub
 
That should have been:
Code:
Private Sub TextBox1_GotFocus(Index As Integer)
If TextBox1(Index).Locked = True Then
    TextBox1(Index).Enabled = False
End If
End Sub

Private Sub TextBox1_LostFocus(Index As Integer)
If TextBox1(Index).Locked = True Then
    TextBox1(Index).Enabled = True
End If
End Sub
 

Try placing your text box on the Frame.

If you set Frame's Enable property to False, all controls on that Frame will look 'normal' but are unavailable to the user.

Have fun.

---- Andy
 


Because any certain control could need this attribute, and under different circumstances a different set of controls, that would mean having a frame for each control.
But, if only one or two controls will need this, or a group of controls with-in the same area, then a frame works fine, which is what I also do in that case.
Which purpose and the number of controls and location needed for this, was not clear from the OP.

 
Thanks Andy and SBerthold.

The frame is pretty near perfect in this case because all those little babies are already on one! I should have thought of that because a I have a couple of disabled Forms in code somewhere which achieve similar stuff.

>That should have been - looks good too for future consideration.

Thanks again to you both, stary, stary night...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top