Textbox Readonly

dzt

Active Member
Licensed User
Catch KeyPressed event and use IgnoreKey

B4X:
[SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][SIZE=2]TextBox1_KeyPress (key)[/SIZE]
[SIZE=2]textbox1.IgnoreKey[/SIZE]
[SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE]

Now only DEL key can change TextBox1.Text
But if you catch LostFocus event too, you can restore it's value again
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
A more simple way is to set the Enabled property to False but still make the textbox visible.
The downside is that it will be slightly greyed out.

Regards,
RandomCoder
 

kyto

Member
Licensed User
Longtime User
An example? Please...

Hi!
Can you give me an example?

But if you catch LostFocus event too, you can restore it's value again

If I have 2 forms, each one with a TextBox, and the text is changed with DEL key;
How to restore the original value of the textbox after having changed one form to other one?

Catch LostFocus event using Refresh?

Thanks for your responses.
 

Attachments

  • demo.sbp
    764 bytes · Views: 185

specci48

Well-Known Member
Licensed User
Longtime User
Hi kyto,

I attached a simple demo2.

If textbox1 gets the focus, the actual value is stored in a global variable. You don't need this, if you have already stored the textbox value in another variable in your appliction.
Change the value of the textbox and click on one of the other controls or somewhere at the main form. Now the lost focus event restores the original value of the textbox.


specci48
 

Attachments

  • demo2.sbp
    936 bytes · Views: 177

kyto

Member
Licensed User
Longtime User
Thanks!

Thanks Specci48!
This is what I needed.
:)
 

Cableguy

Expert
Licensed User
Longtime User
I really don't get it...

Why use a Textbox to show un-editable text??

Isn't that what label are supposed to do?
Is it because of the border around the textbox that the Label don't have??
In that case put a panel slightly larger than the label, under the label, in order tore-create that effect...
With a bonus of not beeing editale, so your text is safe...
 

kyto

Member
Licensed User
Longtime User
Good solution.

I had not thought about that, it looks like to me a good solution, for what also I will try it.

Thanks Cableguy!
:sign0188:
 

specci48

Well-Known Member
Licensed User
Longtime User
Just naming two differences between a label and a (not editable) textbox:

1. a textbox adds scrolbars if needed so you can show much more text an a much smaller space of a form (or panel).

2. if you want to show an unknown (large) text in a label, you probably will get into the problem of the linebreaking on the device (http://www.b4x.com/forum/showthread.php?t=616)
 

Cableguy

Expert
Licensed User
Longtime User
Thank specci48, I hadn't thought about that particular specs of the textbox....
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Another use of a 'locked' textbox is of course to allow different user access.
Some programs might need operator and supervisor access in which the textbox field would be 'locked' to operators but open for supervisors.

Regards,
RandomCoder
 

N1c0_ds

Active Member
Licensed User
All solutions are either easy to go around or display a gray background. After much frustration (it was the last bug left after a bunch of random problems), I found a fix that seems to get the job done:

-Make another textbox and set it as invisible

-Add this code to your app:
B4X:
Sub YourTextbox_Gotfocus
 InvisibleTextbox.Focus
End Sub


Notes: Do not set focus on a form, as it will set focus back to the textbox (and cause a stackoverflowexception of doom)

The drawback:
You can't select text
 
Top