Is there a way to make TextBox text appeared as an asterisk ?

Started by uswin, Mon 11/05/2009 11:54:45

Previous topic - Next topic

uswin

Hi guys, I have one textbox to type a password on it, but is there a way to make the text that I type appeared as an asterisk rather than the actual password ?

Thanks guys really appreciate, cause i've searching around FAQ and forum but couldn't found anything
;D

Gilbert

It can be done with some scripting. However, a simple and sorta cheating way is to make a font set that the characters are all asterisks and make the textbox to use this font set.

Sephiroth

It got me thinking, and I may have a workaround if there's nothing already implemented to do this.

You could create a Gui with one label.
All you'd have to do now is to create a global string UserInput and copy this in the on_key_press section of the global script.

Just replace YourLabel with the ScriptName property of the label.

Code: ags


 if(gGui3.Visible == true)
  {
    int size = UserInput.Length;

    String str2 = YourLabel.Text;
    
    if( keycode == eKeyBackspace && UserInput.Length > 0 )
    {
     UserInput = UserInput.Truncate( size -1 );
     str2 = str2.Truncate( size -1 );
    }

    else if( keycode >= eKey0 && keycode <= eKeyZ)
    {
     UserInput = UserInput.AppendChar( keycode );
     str2 = str2.AppendChar( '*' );
    }

    else if( keycode == eKeyReturn )
    {
      if( UserInput != "BIGBLUECUP" )
      {
        //display a "WRONG PASSWORD" message
      }
      else
      {
        //password matched so do whatever you need.
      }
    }
    YourLabel.Text = str2;
  }

All the letters that are typed will be uppercase, but it could be changed with a few more lines of code.

I also wanted to do this to check what the user's typing letter by letter, but you don't have to use textboxes, a simple label could do.
Edit: Ahh the font trick beats me :)

Pumaman

Quote from: Sephiroth on Mon 11/05/2009 13:58:27
    String str2 = gGui3.Controls[1].AsLabel.Text;

Just to clarify this, a much easier way is to set a script name for your label, then you can just do:

    String str2 = lblLabelName.Text;

instead of messing around with the gui.Controls[] array.

NsMn

Actually, The easiest way to do this is using a Font with just one char for the hole alphabete (e.c. '*'). Try to find/make such a Font, and it would be done.

Sephiroth

Thanks Pumaman, I knew there was a more simple way but couldn't find it, I hadn't seen it in the label properties treeview.
Quoteinstead of messing around with the gui.Controls[] array.
Sorry, I just started using AGS, at least I've learned something useful ;)

uswin

Thanks guys, i will definitely try this, really appreciate  ;D ;D ;D

uswin

guys, thanks u so much, I decided to create a new font with asterisk's only symbol on it, and It worked like a charm, thank u, this idea just didn't pop out of my brain, ehehhe ;D

SMF spam blocked by CleanTalk