Textbox Readonly

Discussion in 'Questions (Windows Mobile)' started by IansResearch, Jun 29, 2007.

  1. IansResearch

    IansResearch Member Licensed User

    Is it possible to make a Multiline Textbox control readonly so that the user cannot change the contents?
     
  2. dzt

    dzt Active Member Licensed User

    Catch KeyPressed event and use IgnoreKey

    Code:
    [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
     
  3. IansResearch

    IansResearch Member Licensed User

    Excellent works great.... :sign0060:

    Thanks
     
  4. RandomCoder

    RandomCoder Well-Known Member Licensed 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
     
  5. kyto

    kyto Member Licensed User

    An example? Please...

    Hi!
    Can you give me an example?

    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.
     

    Attached Files:

    • demo.sbp
      File size:
      764 bytes
      Views:
      20
  6. specci48

    specci48 Well-Known Member Licensed 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
     

    Attached Files:

  7. kyto

    kyto Member Licensed User

    Thanks!

    Thanks Specci48!
    This is what I needed.
    :)
     
  8. Cableguy

    Cableguy Expert Licensed 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...
     
  9. kyto

    kyto Member Licensed 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:
     
  10. specci48

    specci48 Well-Known Member Licensed 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.basic4ppc.com/forum/showthread.php?t=616)
     
  11. Cableguy

    Cableguy Expert Licensed User

    Thank specci48, I hadn't thought about that particular specs of the textbox....
     
  12. RandomCoder

    RandomCoder Well-Known Member Licensed 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
     
  13. N1c0_ds

    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:
    Code:
    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
     
Loading...