17 August 2012

Cross Word Application in C#.Net

Purpose of this Application: “A crossword is a word puzzle that normally takes the form of a square or a rectangular grid of white and shaded squares.” Wikipedia I am very much interested in the Cross Words Games [CWG]. So I developed this Application. 
private static bool chkEmpty;
private static bool IdetifyContNull(System.Windows.Forms.TextBox txt)
{
if (txt.Text == "")
{
chkEmpty = true;
}
else
{
chkEmpty = false;
}
return chkEmpty;
Application Processing:
                   Two Command buttons in the Application. They are QuestionButton and Answer Button.
 Question Button:
  • Clicks “Question” Button.
  • Question will display in the RichTextBox.
Answer Button:
  • ·         Check Answer.
  • ·         Display Message Box.

Now we will go to Coding Section.
 Step by Step Processing
Create a Project in the VS C#.2008.
From name:frmCrossword.cs.
Controls in Application:
    Label, Textboxes, Panel and Buttons.
Class File(s):CheckAnswer.cs
CheckAnswer.cs – Code:
class CheckAnswer
    {
        public  static bool chkAnswer1;
        public static bool chkAnswer2;
        public static bool chkAnswer3;
        public static bool chkAnswer4;
        public static bool chkAnswer5;
        public static bool chkAnswer6;
        public static bool chkAnswer7;
        public static bool chkAnswer8;
        public static bool chkAnswer9;
        public static bool chkLeftToRightQ1(string str)
        {
            if (str == "ABSTRACT")
            {
                chkAnswer1 = true;
            }
            else
            {
                chkAnswer1 = false;
            }
            return chkAnswer1;
        }

        public static bool chkLeftToRightQ18(string str)
        {
            if (str == "SBYTE")
            {
                chkAnswer2 = true;
            }
            else
            {
                chkAnswer2 = false;
            }
            return chkAnswer2;
        }

        public static bool chkLeftToRightQ35(string str)
        {
            if (str == "STRING")
            {
                chkAnswer3 = true;
            }
            else
            {
                chkAnswer3 = false;
            }
            return chkAnswer3;
        }
        public static bool chkLeftToRightQ41(string str)
        {
            if (str == "NEW")
            {
                chkAnswer4 = true;
            }
            else
            {
                chkAnswer4 = false;
            }
            return chkAnswer4;
        }
        public static bool chkTopToBottomQ1(string str)
        {
            if (str == "AS")
            {
                chkAnswer5 = true;
            }
            else
            {
                chkAnswer5 = false;
            }
            return chkAnswer5;
        }

        public static bool chkTopToBottomQ4(string str)
        {
            if (str == "TRY")
            {
                chkAnswer6 = true;
            }
            else
            {
                chkAnswer6 = false;
            }
            return chkAnswer6;
        }

        public static bool chkTopToBottomQ5(string str)
        {
            if (str == "RETURN")
            {
                chkAnswer7 = true;
            }
            else
            {
                chkAnswer7 = false;
            }
            return chkAnswer7;
        }
        public static bool chkTopToBottomQ19(string str)
        {
            if (str == "BASE")
            {
                chkAnswer8 = true;
            }
            else
            {
                chkAnswer8 = false;
            }
            return chkAnswer8;
        }

        public static bool chkTopToBottomQ39(string str)
        {
            if (str == "NULL")
            {
                chkAnswer9 = true;
            }
            else
            {
                chkAnswer9 = false;
            }
            return chkAnswer9;
        }

    }
frmCrossword.cs -- Code   
private void button1_Click(object sender, EventArgs e)
{
CrosswordQuestions();
richTextBox1.ReadOnly = true;
  private void CrosswordQuestions()
{
richTextBox1.SelectedText = Environment.NewLine + "Left To Right";
richTextBox1.ForeColor = Color.Blue;
richTextBox1.SelectedText = Environment.NewLine + "1)An ___________ class can contain either abstract methods or non abstract methods";
richTextBox1.SelectedText = Environment.NewLine + "18) ___________ keyword denotes an integral type that stores values according to the size and range.";
richTextBox1.SelectedText = Environment.NewLine + "35)AlphaNumeric.";
richTextBox1.SelectedText = Environment.NewLine + "41) ______ keyword can be used as an operator or as a modifier Last two letters order changed.";
richTextBox1.SelectedText = Environment.NewLine + "Top To Bottom";
richTextBox1.SelectedText = Environment.NewLine + "1) Which keyword retunr null if a cast will not success?";
richTextBox1.SelectedText = Environment.NewLine + "4) One of the Exception Handling Statement.";
richTextBox1.SelectedText = Environment.NewLine + "5) Terminates execution of the method in which it appears and returns control to the calling method.";
richTextBox1.SelectedText = Environment.NewLine + "19) ____________ keyword is used to access members of the base class from within a derived class.";
richTextBox1.SelectedText = Environment.NewLine + "39) default value of reference-type variables.First two letters order changed.";
private void button2_Click(object sender, EventArgs e)
{
chkStatusofTextBox();
private static bool chkEmpty;
private static bool IdetifyContNull(System.Windows.Forms.TextBox txt)
{
if (txt.Text == "")
{
chkEmpty = true;
}
else
{
chkEmpty = false;
}
return chkEmpty;
      private void  chkStatusofTextBox()
{
bool chkTxt1 = IdetifyContNull(textBox1);
bool chkTxt2 = IdetifyContNull(textBox2);
bool chkTxt3 = IdetifyContNull(textBox3);
bool chkTxt4 = IdetifyContNull(textBox4);
bool chkTxt5 = IdetifyContNull(textBox5);
bool chkTxt6 = IdetifyContNull(textBox6);
bool chkTxt7 = IdetifyContNull(textBox7);
bool chkTxt8 = IdetifyContNull(textBox8);
bool chkTxt9 = IdetifyContNull(textBox24);
bool chkTxt10 = IdetifyContNull(textBox20);
bool chkTxt11 = IdetifyContNull(textBox31);
bool chkTxt12 = IdetifyContNull(textBox30);
bool chkTxt13 = IdetifyContNull(textBox29);
bool chkTxt14 = IdetifyContNull(textBox28);
bool chkTxt15 = IdetifyContNull(textBox27);
bool chkTxt16 = IdetifyContNull(textBox14);
bool chkTxt17 = IdetifyContNull(textBox12);
bool chkTxt18 = IdetifyContNull(textBox10);
bool chkTxt19 = IdetifyContNull(textBox38);
bool chkTxt20 = IdetifyContNull(textBox37);
bool chkTxt21 = IdetifyContNull(textBox36);
bool chkTxt22 = IdetifyContNull(textBox35);
bool chkTxt23 = IdetifyContNull(textBox34);
bool chkTxt24 = IdetifyContNull(textBox33);
bool chkTxt25 = IdetifyContNull(textBox48);
bool chkTxt26 = IdetifyContNull(textBox47);
bool chkTxt27 = IdetifyContNull(textBox46);
bool chkTxt28 = IdetifyContNull(textBox44);
bool chkTxt29 = IdetifyContNull(textBox42);
bool chkTxt30 = IdetifyContNull(textBox50);
if ((chkTxt1) || (chkTxt2) || (chkTxt3) || (chkTxt4) || (chkTxt5) || (chkTxt6) || (chkTxt7) || (chkTxt8) || (chkTxt9) || (chkTxt10) || (chkTxt11) || (chkTxt12) || (chkTxt13) || (chkTxt14) || (chkTxt15) || (chkTxt16) || (chkTxt17) || (chkTxt18) || (chkTxt19) || (chkTxt20) || (chkTxt21) || (chkTxt22) || (chkTxt23) || (chkTxt24) || (chkTxt25) || (chkTxt26) || (chkTxt27) || (chkTxt28) || (chkTxt29) || (chkTxt30))
{
MessageBox.Show("Please give all values in the Input Box");
}
else
{
checkAnswer();
}

private void checkAnswer()
{
// Left To Right Q1
string userValue1 = getTextValue(textBox1).ToUpper();
string userValue2 = getTextValue(textBox2).ToUpper();
string userValue3 = getTextValue(textBox3).ToUpper();
string userValue4 = getTextValue(textBox4).ToUpper();
string userValue5 = getTextValue(textBox5).ToUpper();
string userValue6 = getTextValue(textBox6).ToUpper();
string userValue7 = getTextValue(textBox7).ToUpper();
string userValue8 = getTextValue(textBox8).ToUpper();
// Left To Right Q2
string userValue9 = getTextValue(textBox31).ToUpper();
string userValue10 = getTextValue(textBox30).ToUpper();
string userValue11 = getTextValue(textBox29).ToUpper();
string userValue12 = getTextValue(textBox28).ToUpper();
string userValue13 = getTextValue(textBox27).ToUpper();
// Left To Right Q3
string userValue14 = getTextValue(textBox38).ToUpper();
string userValue15 = getTextValue(textBox37).ToUpper();
string userValue16 = getTextValue(textBox36).ToUpper();
string userValue17 = getTextValue(textBox35).ToUpper();
string userValue18 = getTextValue(textBox34).ToUpper();
string userValue19 = getTextValue(textBox33).ToUpper();
// Left To Right Q4
string userValue20 = getTextValue(textBox18).ToUpper();
string userValue21 = getTextValue(textBox17).ToUpper();
string userValue22 = getTextValue(textBox16).ToUpper();
// Top To Bottom Q1
string userValue23 = getTextValue(textBox1).ToUpper();
string userValue24 = getTextValue(textBox24).ToUpper();
// Top To Bottom Q2
string userValue25 = getTextValue(textBox4).ToUpper();
string userValue26 = getTextValue(textBox21).ToUpper();
string userValue27 = getTextValue(textBox29).ToUpper();
// Top To Bottom Q3
string userValue28 = getTextValue(textBox5).ToUpper();
string userValue29 = getTextValue(textBox20).ToUpper();
string userValue30 = getTextValue(textBox28).ToUpper();
string userValue31 = getTextValue(textBox12).ToUpper();
string userValue32 = getTextValue(textBox36).ToUpper();
string userValue33 = getTextValue(textBox44).ToUpper();
// Top To Bottom Q4
string userValue34 = getTextValue(textBox30).ToUpper();
string userValue35 = getTextValue(textBox14).ToUpper();
string userValue36 = getTextValue(textBox38).ToUpper();
string userValue37 = getTextValue(textBox46).ToUpper();
// Top To Bottom Q5
string userValue38 = getTextValue(textBox34).ToUpper();
string userValue39 = getTextValue(textBox10).ToUpper();
string userValue40 = getTextValue(textBox42).ToUpper();
string userValue41 = getTextValue(textBox50).ToUpper();
/// Verify Answer
string userAnswer1 = userValue1 + userValue2 + userValue3 + userValue4 + userValue5 + userValue6 + userValue7 + userValue8;
string userAnswer2 = userValue9 + userValue10 + userValue11 + userValue12 + userValue13;
string userAnswer3 = userValue14 + userValue15 + userValue16 + userValue17 + userValue18 + userValue19;
string userAnswer4 = userValue20 + userValue21 + userValue22;
string userAnswer5 = userValue23 + userValue24;
string userAnswer6 = userValue25 + userValue26 + userValue27;
string userAnswer7 = userValue28 + userValue29 + userValue30 + userValue31 + userValue32 + userValue33;
string userAnswer8 = userValue34 + userValue35 + userValue36 + userValue37;
string userAnswer9 = userValue38 + userValue39 + userValue40 + userValue41;
/// Check Answer from Left TO Right
bool chkAns1 = CheckAnswer.chkLeftToRightQ1(userAnswer1);
bool chkAns4 = CheckAnswer.chkLeftToRightQ18(userAnswer2);
bool chkAns3 = CheckAnswer.chkLeftToRightQ35(userAnswer3);
bool chkAns2 = CheckAnswer.chkLeftToRightQ41(userAnswer4);
/// Check Answer from Top To Bottom
bool chkAns5 = CheckAnswer.chkTopToBottomQ1(userAnswer5);
bool chkAns8 = CheckAnswer.chkTopToBottomQ4(userAnswer6);
bool chkAns9 = CheckAnswer.chkTopToBottomQ5(userAnswer7);
bool chkAns6 = CheckAnswer.chkTopToBottomQ19(userAnswer8);
bool chkAns7 = CheckAnswer.chkTopToBottomQ39(userAnswer9);
if ((chkAns1) && (chkAns2) && (chkAns3) && (chkAns4) && (chkAns5) && (chkAns6) && (chkAns7) && (chkAns8) && (chkAns9))
{
MessageBox.Show("Answers are Right");
}
else
{
MessageBox.Show("Answers are Wrong");
}
}


private static string str;
private static string getTextValue(TextBox txt)
{
str = txt.Text;
return str;
}
 
 
 

No comments: