Posts Tagged ‘C#’

Tutorial #3 – Pizza Order in C#

November 11th, 2008 1 comment

Here is my new pizza order tutorial for you. In this tutorial you are able to control checkboxes and radiobuttons together and show them into a message box window.

Codes below…

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
public partial class pizza : Form

//Some global strings to keep radiobutton and checkbox events text's.
private String a1 = null;
private String a2 = null;
private String a3 = null;
private String menu = null;

public pizza()

Read more…

VN:F [1.9.22_1171]
Rating: 5.9/10 (9 votes cast)
VN:F [1.9.22_1171]
Rating: -1 (from 1 vote)
Categories: C#, Programming Tags: , , ,

Tutorial #2 – Basic Guess Game in C#

November 10th, 2008 No comments

Here is my new tutorial for you about C#. In this tutorial i am going to make a little game about guessing result of some number summation, multiplation, division and addition. And i am going to focus on handling the enter keypress event for textfield.

Here as you see from the screenshot of the main window a user should guess the result of this operation. Textbox1 equals the random number “96″, textbox2 equals the random number “73″ and there is an randomly operator which is “-” . User should guess this result and should write down the guess into the textbox3 field. When user press enter button textbox3 handles this event.

private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
if (e.KeyChar == (char)13) //Char 13 handles the enter key
Console.WriteLine(total);  //Here i can check the result from console for testing purposes
if (total.ToString() == textBox3.Text)
StringBuilder dogru_str = new StringBuilder();
dogru_str.Append(" " + label1.Text + " ");
dogru_str.Append(textBox2.Text + " = ");
dogru_str.Append(total + "\n");
dogru_str.Append("Your answer was correct...");
MessageBox.Show(dogru_str.ToString(), "Result", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

Read more…

VN:F [1.9.22_1171]
Rating: 9.8/10 (4 votes cast)
VN:F [1.9.22_1171]
Rating: -1 (from 1 vote)

Tutorial #1 – Random Function in C#

November 9th, 2008 No comments

Since there are some other ways as well. Here is my little function which can generate a random integer

private int RandomNumber(int min, int max)
Random random = new Random();
int rand = random.Next(min, max);
return rand;

I need to convert this interger number to a string. And this function takes to parameters minimum & maximum. That helps you to determine the interval of this random numbers.

//Determine about operator
String[] operators = { "+", "-", "/", "*" };
int rand3 = random.Next(1, 5);
switch (rand3.ToString())
case "1":
label1.Text = "+";
total = rand1 + rand2;
case "2":
label1.Text = "-";
total = rand1 - rand2;
case "3":
label1.Text = "/";
total = rand1 / rand2;
case "4":
label1.Text = "*";
total = rand1 * rand2;
label1.Text = "Error";

Read more…

VN:F [1.9.22_1171]
Rating: 1.0/10 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Categories: C#, Programming Tags: , ,