Wednesday, June 9, 2010

A Simple Hangman Program (Revision on String methods)

This program uses string array, Keypress event’s  KeyChar, SubString(), Remove() and Insert(). 

Also, it illustrates the use of #region & #endregion to organize your codes.

Add a new project with the following controls:

  • Two textboxes (ReadOnly=true)
  • Two labels with text as shown below
  • Form1 (KeyPreview = true)

image

Add codes:

(Click on the images to view in full)

(1) Declare variables and create the required stuff in Form1_Load method:

image

(2)  Add Form1_KeyPress event handler:

image

(2A)  Add in the codes for “Check the character being pressed”

image

(2B) Post check processing

image

Try it!

0 comments:

Post a Comment