make a simple game like mastermindbit more involved and interesting but wont take long.
Make a program that counts the number of characters in a sentence.
I recommend this because it can be done in many different ways, and is fairly simple to make.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace letter_counters
{
public partial class Sentence : Form
{
public Sentence()
{
InitializeComponent();
}
string Tlength = "";
int stirTin = 0;
string Count = "";
private void txtbSen_TextChanged(object sender, EventArgs e)
{
}
private void btnEnter_Click(object sender, EventArgs e)
{
Tlength = txtbSen.Text.ToString();
stirTin = System.Convert.ToInt32(Tlength.Length);
Count = stirTin.ToString();
MessageBox.Show(Count);
}
}
}
private void InitializeComponent()
{
this.btnEnter = new System.Windows.Forms.Button();
this.lblSen = new System.Windows.Forms.Label();
this.txtbSen = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// btnEnter
//
this.btnEnter.Location = new System.Drawing.Point(16, 44);
this.btnEnter.Name = "btnEnter";
this.btnEnter.Size = new System.Drawing.Size(75, 23);
this.btnEnter.TabIndex = 0;
this.btnEnter.Text = "Submit";
this.btnEnter.UseVisualStyleBackColor = true;
this.btnEnter.Click += new System.EventHandler(this.btnEnter_Click);
//
// lblSen
//
this.lblSen.AutoSize = true;
this.lblSen.Location = new System.Drawing.Point(13, 13);
this.lblSen.Name = "lblSen";
this.lblSen.Size = new System.Drawing.Size(86, 13);
this.lblSen.TabIndex = 1;
this.lblSen.Text = "Enter Characters";
//
// txtbSen
//
this.txtbSen.Location = new System.Drawing.Point(105, 10);
this.txtbSen.Name = "txtbSen";
this.txtbSen.Size = new System.Drawing.Size(594, 20);
this.txtbSen.TabIndex = 2;
this.txtbSen.TextChanged += new System.EventHandler(this.txtbSen_TextChanged);
//
// Sentence
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(711, 79);
this.Controls.Add(this.txtbSen);
this.Controls.Add(this.lblSen);
this.Controls.Add(this.btnEnter);
this.Name = "Sentence";
this.Text = "Sentence";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button btnEnter;
private System.Windows.Forms.Label lblSen;
private System.Windows.Forms.TextBox txtbSen;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace more_forms
{
public partial class calculator : Form
{
public calculator()
{
InitializeComponent();
}
//Addition Private Function
private void addition(int abox, int bbox)
{
// setting an int to 0 so that ints a + b can be added and the result shown will be assaigned to this int
int result = 0;
// the addition of a + b shoiwn in int result
result = abox + bbox;
//displaying the information of the calculation then converting it into a text and assaigning it a string to display
lblttl.Text = result.ToString();
}
//Subtract Private Function
private void subtraction(int abox, int bbox)
{
int result = 0;
result = abox - bbox;
lblttl.Text = result.ToString();
}
//Multiplication Private Function
private void multiplication(int abox, int bbox)
{
int result = 0;
result = abox * bbox;
lblttl.Text = result.ToString();
}
//Division Private Function
private void division(int abox, int bbox)
{
int result = 0;
result = abox / bbox;
lblttl.Text = result.ToString();
}
private void Form2_Load(object sender, EventArgs e)
{
}
//Addition Button
private void btnAdd_Click(object sender, EventArgs e)
{
//naming the int's that the data is eventualy going to be converted to
int firstbox = 0;
int secondbox = 0;
//this is trying a function then if not it will catch the rest and siplay something else
try
{
//this is converting the text (string) from txtAd1 to an int so the calculation can be done in a different function all this click is doing is slecting a seperate function
firstbox = System.Convert.ToInt32(txtAd1.Text);
secondbox = System.Convert.ToInt32(txtAd2.Text);
lblInf.Text = "Completed MOFO!";
}
catch
{
lblInf.Text = "ERROR";
}
addition(firstbox, secondbox);
}
//Subtraction Button
private void btnsubb_Click(object sender, EventArgs e)
{
int firstbox = 0;
int secondbox = 0;
try
{
firstbox = System.Convert.ToInt32(txtAd1.Text);
secondbox = System.Convert.ToInt32(txtAd2.Text);
lblInf.Text = "Everything is A OK";
}
catch
{
lblInf.Text = "Uh oh";
}
subtraction(firstbox, secondbox);
}
//Multiplication Button
private void btnmulti_Click(object sender, EventArgs e)
{
int firstbox = 0;
int secondbox = 0;
try
{
firstbox = System.Convert.ToInt32(txtAd1.Text);
secondbox = System.Convert.ToInt32(txtAd2.Text);
lblInf.Text = "Success!";
}
catch
{
lblInf.Text = "Ooops Error!";
}
multiplication(firstbox, secondbox);
}
//Division Button
private void btndiv_Click(object sender, EventArgs e)
{
int firstbox = 0;
int secondbox = 0;
try
{
firstbox = System.Convert.ToInt32(txtAd1.Text);
secondbox = System.Convert.ToInt32(txtAd2.Text);
lblInf.Text = "Sucess";
}
catch
{
lblInf.Text = "Something is wrong!";
}
division(firstbox, secondbox);
}
}
}
private void InitializeComponent()
{
this.txtAd1 = new System.Windows.Forms.TextBox();
this.txtAd2 = new System.Windows.Forms.TextBox();
this.lblttl = new System.Windows.Forms.Label();
this.lblCalc = new System.Windows.Forms.Label();
this.lblInf = new System.Windows.Forms.Label();
this.btnAdd = new System.Windows.Forms.Button();
this.btnsubb = new System.Windows.Forms.Button();
this.btnmulti = new System.Windows.Forms.Button();
this.btndiv = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// txtAd1
//
this.txtAd1.Location = new System.Drawing.Point(94, 12);
this.txtAd1.Name = "txtAd1";
this.txtAd1.Size = new System.Drawing.Size(100, 20);
this.txtAd1.TabIndex = 0;
//
// txtAd2
//
this.txtAd2.Location = new System.Drawing.Point(94, 38);
this.txtAd2.Name = "txtAd2";
this.txtAd2.Size = new System.Drawing.Size(100, 20);
this.txtAd2.TabIndex = 1;
//
// lblttl
//
this.lblttl.AutoSize = true;
this.lblttl.Location = new System.Drawing.Point(140, 72);
this.lblttl.Name = "lblttl";
this.lblttl.Size = new System.Drawing.Size(0, 13);
this.lblttl.TabIndex = 2;
//
// lblCalc
//
this.lblCalc.AutoSize = true;
this.lblCalc.Location = new System.Drawing.Point(27, 72);
this.lblCalc.Name = "lblCalc";
this.lblCalc.Size = new System.Drawing.Size(84, 13);
this.lblCalc.TabIndex = 3;
this.lblCalc.Text = "Final Calculation";
//
// lblInf
//
this.lblInf.AutoSize = true;
this.lblInf.Location = new System.Drawing.Point(124, 117);
this.lblInf.Name = "lblInf";
this.lblInf.Size = new System.Drawing.Size(0, 13);
this.lblInf.TabIndex = 4;
//
// btnAdd
//
this.btnAdd.Location = new System.Drawing.Point(13, 176);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(75, 23);
this.btnAdd.TabIndex = 5;
this.btnAdd.Text = "Add";
this.btnAdd.UseVisualStyleBackColor = true;
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// btnsubb
//
this.btnsubb.Location = new System.Drawing.Point(13, 205);
this.btnsubb.Name = "btnsubb";
this.btnsubb.Size = new System.Drawing.Size(75, 23);
this.btnsubb.TabIndex = 6;
this.btnsubb.Text = "Subtraction";
this.btnsubb.UseVisualStyleBackColor = true;
this.btnsubb.Click += new System.EventHandler(this.btnsubb_Click);
//
// btnmulti
//
this.btnmulti.Location = new System.Drawing.Point(198, 176);
this.btnmulti.Name = "btnmulti";
this.btnmulti.Size = new System.Drawing.Size(82, 23);
this.btnmulti.TabIndex = 7;
this.btnmulti.Text = "Multiplication";
this.btnmulti.UseVisualStyleBackColor = true;
this.btnmulti.Click += new System.EventHandler(this.btnmulti_Click);
//
// btndiv
//
this.btndiv.Location = new System.Drawing.Point(198, 204);
this.btndiv.Name = "btndiv";
this.btndiv.Size = new System.Drawing.Size(82, 23);
this.btndiv.TabIndex = 8;
this.btndiv.Text = "Division";
this.btndiv.UseVisualStyleBackColor = true;
this.btndiv.Click += new System.EventHandler(this.btndiv_Click);
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.btndiv);
this.Controls.Add(this.btnmulti);
this.Controls.Add(this.btnsubb);
this.Controls.Add(this.btnAdd);
this.Controls.Add(this.lblInf);
this.Controls.Add(this.lblCalc);
this.Controls.Add(this.lblttl);
this.Controls.Add(this.txtAd2);
this.Controls.Add(this.txtAd1);
this.Name = "Form2";
this.Text = "Form2";
this.Load += new System.EventHandler(this.Form2_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox txtAd1;
private System.Windows.Forms.TextBox txtAd2;
private System.Windows.Forms.Label lblttl;
private System.Windows.Forms.Label lblCalc;
private System.Windows.Forms.Label lblInf;
private System.Windows.Forms.Button btnAdd;
private System.Windows.Forms.Button btnsubb;
private System.Windows.Forms.Button btnmulti;
private System.Windows.Forms.Button btndiv;
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
namespace new_write_xml
{
public partial class Form1 : Form
{
//strings needed for the program
string filename = "";
bool pass = false;
string comboS = "";
string combFav = "";
string totalDest = "";
public Form1()
{
InitializeComponent();
}
//creating the file name and validating it
private void btnsub_Click(object sender, EventArgs e)
{
filename = txtbFName.Text.ToString();
//checks if nothing has been enterd
if (filename == "")
{
MessageBox.Show("please enter a file name ");
//creates the statement of false so the user cannot progress to the next level
pass = false;
}
// if the file then has words inputted into the text box it will then go to the following statements
else
{
//checks if the file exists
if (!File.Exists(@"C:\XML\" + filename + ".xml"))
{
MessageBox.Show("File Not In Existance, however its now been created");
//creates an xml file
//XmlTextWriter writer = new XmlTextWriter(@"C:\XML\" + filename + ".xml", new System.Text.ASCIIEncoding());
pass = true;
}
else
{
MessageBox.Show("File Already Exists! please create another");
pass = false;
}
}
}
//submitting the data to the xml document
private void button1_Click(object sender, EventArgs e)
{
//try and catch stop the error in progress for instance symbols in the file name
try
{
// if the bool pass variable has been changed then it will allow the submit
totalDest = @"C:\XML\" + filename + ".xml";
if (pass == true)
{
//this is where the document is created
//gives the format of encoding
XmlTextWriter writer = new XmlTextWriter(totalDest, new System.Text.ASCIIEncoding());
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.WriteStartDocument();
//opening tags
writer.WriteStartElement("OpenXML");
//this is an if statement to select if the participant is over 18, through radio buttons
if (rbYes.Checked)
{
writer.WriteElementString("OVER18", "Yes");
//MessageBox.Show("your over 18");
}
else
{
writer.WriteElementString("OVER18", "No");
//MessageBox.Show("your not over 18");
}
//putting the combo box that contains the fave drink to text
combFav = cbFav.Text.ToString();
writer.WriteElementString("FavDrink", combFav);
//MessageBox.Show(combFav);
//track bar status less than 5
if (tbLike.Value < 5)
{
writer.WriteElementString("LikeDrink", "You dont like " + combFav + "very much");
// MessageBox.Show("you dont like " + combFav + " very much");
}
//track bar status more than 5
if (tbLike.Value > 5)
{
writer.WriteElementString("LikeDrink", "You think " + combFav + "is amazing!");
//MessageBox.Show("you think " + combFav + " is amazing");
}
//this goes through the combo box and selects each ticked and sends it to a string INDIVIDUALY not all together
writer.WriteStartElement("Drink");
for (int i = 0; i < clBooze.Items.Count; i++)
{
if (clBooze.GetItemChecked(i))
{
comboS = clBooze.Items[i].ToString();
writer.WriteElementString("", comboS);
//MessageBox.Show(comboS);
}
}
//closing the tags
writer.WriteEndElement();
writer.Flush();
//closeing the writer
writer.Close();
}
// if submit to filename desination has been pressed with nothing in etc ....
else
{
MessageBox.Show("Something is wrong !");
}
}
catch (Exception EX)
{
//display whats wrong
MessageBox.Show(EX.Message);
}
}
}
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.txtbFName = new System.Windows.Forms.TextBox();
this.btnsub = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.rbNo = new System.Windows.Forms.RadioButton();
this.rbYes = new System.Windows.Forms.RadioButton();
this.cbFav = new System.Windows.Forms.ComboBox();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.clBooze = new System.Windows.Forms.CheckedListBox();
this.tbLike = new System.Windows.Forms.TrackBar();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.groupBox5 = new System.Windows.Forms.GroupBox();
this.button1 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.tbLike)).BeginInit();
this.groupBox4.SuspendLayout();
this.groupBox5.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.txtbFName);
this.groupBox1.Controls.Add(this.btnsub);
this.groupBox1.Location = new System.Drawing.Point(12, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(581, 83);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "File Name";
//
// txtbFName
//
this.txtbFName.Location = new System.Drawing.Point(7, 28);
this.txtbFName.Name = "txtbFName";
this.txtbFName.Size = new System.Drawing.Size(568, 20);
this.txtbFName.TabIndex = 1;
//
// btnsub
//
this.btnsub.Location = new System.Drawing.Point(7, 54);
this.btnsub.Name = "btnsub";
this.btnsub.Size = new System.Drawing.Size(85, 23);
this.btnsub.TabIndex = 0;
this.btnsub.Text = "Submit";
this.btnsub.UseVisualStyleBackColor = true;
this.btnsub.Click += new System.EventHandler(this.btnsub_Click);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.rbNo);
this.groupBox2.Controls.Add(this.rbYes);
this.groupBox2.Location = new System.Drawing.Point(12, 101);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(121, 83);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Are Yo Over 18 ?";
//
// rbNo
//
this.rbNo.AutoSize = true;
this.rbNo.Location = new System.Drawing.Point(7, 43);
this.rbNo.Name = "rbNo";
this.rbNo.Size = new System.Drawing.Size(39, 17);
this.rbNo.TabIndex = 1;
this.rbNo.TabStop = true;
this.rbNo.Text = "No";
this.rbNo.UseVisualStyleBackColor = true;
//
// rbYes
//
this.rbYes.AutoSize = true;
this.rbYes.Location = new System.Drawing.Point(7, 19);
this.rbYes.Name = "rbYes";
this.rbYes.Size = new System.Drawing.Size(43, 17);
this.rbYes.TabIndex = 0;
this.rbYes.TabStop = true;
this.rbYes.Text = "Yes";
this.rbYes.UseVisualStyleBackColor = true;
//
// cbFav
//
this.cbFav.FormattingEnabled = true;
this.cbFav.Items.AddRange(new object[] {
"Stella",
"Blue WKD",
"IRON WKD",
"Vodka & Coke",
"Jack Daniels",
"Paint Thinner",
"Mojo",
"Skittles",
"John Smiths",
"Kronenburg",
"Fosters",
"Carling",
"Magners",
"Southern Comfort"});
this.cbFav.Location = new System.Drawing.Point(55, 29);
this.cbFav.Name = "cbFav";
this.cbFav.Size = new System.Drawing.Size(321, 21);
this.cbFav.TabIndex = 2;
//
// groupBox3
//
this.groupBox3.Controls.Add(this.cbFav);
this.groupBox3.Location = new System.Drawing.Point(140, 101);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(453, 83);
this.groupBox3.TabIndex = 3;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Choose a Drink ?";
//
// clBooze
//
this.clBooze.FormattingEnabled = true;
this.clBooze.Items.AddRange(new object[] {
"Absinthe",
"Brandy",
"Ameretto",
"Cognac",
"Godons Gin",
"Vat 19",
"Bacardi Golden Rum",
"Lambs",
"Havana Club",
"Tequila",
"Baileys",
"Dooleys",
"Peach Schnapps",
"Champagne",
"Ale",
"White Wine",
"Red Whine",
"Rose",
"BuksFiz",
"Kopperburg"});
this.clBooze.Location = new System.Drawing.Point(6, 19);
this.clBooze.Name = "clBooze";
this.clBooze.Size = new System.Drawing.Size(222, 154);
this.clBooze.TabIndex = 4;
//
// tbLike
//
this.tbLike.Location = new System.Drawing.Point(17, 30);
this.tbLike.Name = "tbLike";
this.tbLike.Size = new System.Drawing.Size(210, 45);
this.tbLike.TabIndex = 5;
this.tbLike.Value = 5;
//
// groupBox4
//
this.groupBox4.Controls.Add(this.label2);
this.groupBox4.Controls.Add(this.label1);
this.groupBox4.Controls.Add(this.tbLike);
this.groupBox4.Location = new System.Drawing.Point(12, 191);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(241, 100);
this.groupBox4.TabIndex = 6;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "How much do you like this drink ?";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(6, 68);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(46, 13);
this.label2.TabIndex = 9;
this.label2.Text = "Its Crap!";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(196, 68);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(39, 13);
this.label1.TabIndex = 6;
this.label1.Text = "Loads!";
//
// groupBox5
//
this.groupBox5.Controls.Add(this.clBooze);
this.groupBox5.Location = new System.Drawing.Point(307, 191);
this.groupBox5.Name = "groupBox5";
this.groupBox5.Size = new System.Drawing.Size(237, 186);
this.groupBox5.TabIndex = 7;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "What else do you like ? ";
//
// button1
//
this.button1.Location = new System.Drawing.Point(12, 427);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(581, 188);
this.button1.TabIndex = 8;
this.button1.Text = "Submit!";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(605, 627);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox5);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.groupBox3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.tbLike)).EndInit();
this.groupBox4.ResumeLayout(false);
this.groupBox4.PerformLayout();
this.groupBox5.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button btnsub;
private System.Windows.Forms.TextBox txtbFName;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.RadioButton rbNo;
private System.Windows.Forms.RadioButton rbYes;
private System.Windows.Forms.ComboBox cbFav;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.CheckedListBox clBooze;
private System.Windows.Forms.TrackBar tbLike;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.GroupBox groupBox5;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;