Windows Forms


Introduction

This article helps for the beginner. A small game designed using simple text box, button and dropdown list the first add text box , drop down list and submit button as show below


 
Form1.cs

using System;<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

 

namespace smallgame

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            label1.Text="Try to get 56 in all the blue boxes,\n";

            label1.Text+= "using the pull-down lists!";

        }

        private int con(string P)

        {

            int x = Convert.ToInt16(P);

            return x;

        }

        private void button1_Click(object sender, EventArgs e)

        {

            // int x = con(cb1.SelectedItem )+ con(cb2.SelectedItem);

            //row sum

          

            int x1 = Convert.ToInt16(cb1.SelectedItem);

            int x2 = Convert.ToInt16(cb5.SelectedItem);

            int x3 = Convert.ToInt16(cb9.SelectedItem);

            int x4 = Convert.ToInt16(cb13.SelectedItem);

            int sx = x1 + x2 + x3 + x4;

            t2.Text = Convert.ToString(sx);

            t15.Text = Convert.ToString(sx);
 

            int y1 = Convert.ToInt16(cb2.SelectedItem);

            int y2 = Convert.ToInt16(cb6.SelectedItem);

            int y3 = Convert.ToInt16(cb10.SelectedItem);

            int y4 = Convert.ToInt16(cb14.SelectedItem);

            int sy = y1 + y2 + y3 + y4;

            t3.Text = Convert.ToString(sy);

            t14.Text=Convert.ToString(sy);

 

            int z1 = Convert.ToInt16(cb3.SelectedItem);

            int z2 = Convert.ToInt16(cb7.SelectedItem);

            int z3 = Convert.ToInt16(cb11.SelectedItem);

            int z4 = Convert.ToInt16(cb15.SelectedItem);

            int sz = z1 + z2 + z3 + z4;

            t4.Text = Convert.ToString(sz);

            t13.Text = Convert.ToString(sz);

 

            int p1 = Convert.ToInt16(cb4.SelectedItem);

            int p2 = Convert.ToInt16(cb8.SelectedItem);

            int p3 = Convert.ToInt16(cb12.SelectedItem);

            int p4 = Convert.ToInt16(cb16.SelectedItem);

            int sp = p1 + p2 + p3 + p4;

            t5.Text = Convert.ToString(sp);

            t12.Text = Convert.ToString(sp);

           

            //col sum

            int a1 = Convert.ToInt16(cb1.SelectedItem);

            int a2 = Convert.ToInt16(cb2.SelectedItem);

            int a3 = Convert.ToInt16(cb3.SelectedItem);

            int a4 = Convert.ToInt16(cb4.SelectedItem);

            int sa = a1 + a2 + a3 + a4;

            t20.Text = Convert.ToString(sa);

            t7.Text = Convert.ToString(sa);

 

            int b1 = Convert.ToInt16(cb5.SelectedItem);

            int b2 = Convert.ToInt16(cb6.SelectedItem);

            int b3 = Convert.ToInt16(cb7.SelectedItem);

            int b4 = Convert.ToInt16(cb8.SelectedItem);

            int sb = b1 + b2 + b3 + b4;

            t19.Text = Convert.ToString(sb);

            t8.Text = Convert.ToString(sb);

 

            int c1 = Convert.ToInt16(cb9.SelectedItem);

            int c2 = Convert.ToInt16(cb10.SelectedItem);

            int c3 = Convert.ToInt16(cb11.SelectedItem);

            int c4 = Convert.ToInt16(cb12.SelectedItem);

            int sc= y1 + y2 + y3 + y4;

            t18.Text = Convert.ToString(sc);

            t9.Text = Convert.ToString(sc);

 

            int d1 = Convert.ToInt16(cb13.SelectedItem);

            int d2 = Convert.ToInt16(cb14.SelectedItem);

            int d3 = Convert.ToInt16(cb15.SelectedItem);

            int d4 = Convert.ToInt16(cb16.SelectedItem);

            int sd = d1 + d2 + d3 + d4;

            t17.Text = Convert.ToString(sd);

            t10.Text = Convert.ToString(sd);

 

            int dd1 = Convert.ToInt16(cb1.SelectedItem);

            int dd2 = Convert.ToInt16(cb6.SelectedItem);

            int dd3 = Convert.ToInt16(cb11.SelectedItem);

            int dd4 = Convert.ToInt16(cb16.SelectedItem);

            int ddc = dd1 + dd2 + dd3 + dd4;

            tt1.Text = Convert.ToString(ddc);

            tt3.Text = Convert.ToString(ddc);

 

 

            int ddd1 = Convert.ToInt16(cb13.SelectedItem);

            int ddd2 = Convert.ToInt16(cb10.SelectedItem);

            int ddd3 = Convert.ToInt16(cb7.SelectedItem);

            int ddd4 = Convert.ToInt16(cb4.SelectedItem);

            int dddc = ddd1 + ddd2 + ddd3 + ddd4;

            tt2.Text = Convert.ToString(dddc);

            tt4.Text = Convert.ToString(dddc);

 

            // t2.Text = Convert.ToString( con(cb1.SelectedItem)+con(cb5.SelectedItem)+con(cb9.SelectedItem));

            int flag = 0,x=0;

           

            int[] a = new int[12];

            a[0] = sx; a[1] = sy; a[2] = sz; a[3] = sz;

            a[4] = sa; a[5] = sb; a[6] = sc; a[7] = sd; a[8] = sp; a[9] = 56; a[10] = ddc; a[11] = dddc;

            for (int i = 0; i < 10; i++)

           

                if (a[i] == a[i + 1])

                {

                    flag = 0;

                }

                else  x=1; 

            }

            if (flag == 0 && x==0)

            {

                //MessageBox.Show("Congrats Dude your the winner", MessageBoxIcon.Hand);

                MessageBox.Show("Congrats Dude you r the winner\n\n\n By\n-veeru", "Have a Nice Time", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

            else if(x==1)

            {

                MessageBox.Show("wrong answer please try again");

            }

        }

    }
}

Up Next
    Ebook Download
    View all
    Learn
    View all