Blue Theme Orange Theme Green Theme Red Theme
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Team Foundation Server Hosting
Search :       Advanced Search »
Home » Windows Forms C# » Windows Forms

Windows Forms

This article shows you a small game by using simple text box ,buttons and dropdown list.

Page Views : 9861
Downloads : 278
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
smallgame.zip
 
 
DevExpress Free UI Controls
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

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");

            }

        }

    }
}

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Veeresh i
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the Top 5 .NET Memory Management Fundamentals
To write the best .NET code, you need to know exactly how the .NET framework really manages memory. Ricky Leeks presents the Top 5 fundamental facts of .NET memory management. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Team Foundation Server Hosting
Become a Sponsor
 Comments
hi by abhi On October 12, 2010
Will you plz help me to synchronize data for windows ce and create a application in windows ce im not getting it plz
Reply | Email | Modify 
Team Foundation Server Hosting
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.