Problem with hangman

chocopop

Newcomer
Joined
Feb 25, 2003
Messages
2
I am trying to make a hangman project where it will pull a random word from a text file and then display the word in a text box. Obviously with the point of Hangman the letters cant be visable so I want for each letter of the word a "*" to appear

for example

fish = ****
dog = ***

Ok now with that said i have a random word sitting in a string called myWord I just need to display that word with asterics in txtWord.text


If you guys could help me get past this bump id appreciate it
 
There are several ways you can do this.

If ALL you want to show up is asterisks, no matter what, then
set the PasswordChar property of the TextBox to "*", and then
any character in the textbox will be represented by a *.

If you want to change the text in the textbox later to show some
actual letters, then you can use the String's constructor to
deuplicate the * character a certain number of times.

Visual Basic:
' Method #1:
txtWord.PasswordChar = "*"c
txtWord.Text = myWord

' Method #2:
txtWord.Text = New String("*"c, myWord.Length)

Or, in C#:

C#:
// Method #1:
txtWord.PasswordChar = '*';
txtWord.Text = myWord;

// Method #2:
txtWord.Text = new string('*', myWord.Length);
 
Thanks for the help be neither of those ways is how i chose to do it.

I dont have the proj saved at home, but for future refrense that if you use the password char it will not allow you to change it back when they guess the correct letter
 
Back
Top