Showing posts with label C# Corner. Show all posts
Showing posts with label C# Corner. Show all posts

Thursday, 20 June 2013

How to make programmable thermometer by C# | Code

How to make programmable thermometer by  C# | Code

How to make programmable thermometer by  C# | Code


For Fahrenheit to Centigrade we set the value of Fahrenheit from track bar and convert this value into Centigrade using this formula C= (F-32)*(5/9).
private void trackBar1_Scroll(object sender, EventArgs e)
        {
            maskedTextBox1.Text = (trackBar1.Value).ToString();
            double change = (trackBar1.Value - 32) * (5.0 / 9.0);
            change = Math.Round(change, 2);
            maskedTextBox2.Text = change.ToString();
        }
For Centigrade to Fahrenheit we set the value of Centigrade from track bar and convert this value into Fahrenheit using this formula F= (C* (9/5)) +32.
private void trackBar2_Scroll_1(object sender, EventArgs e)
        {
            maskedTextBox3.Text = (trackBar2.Value).ToString();
            maskedTextBox4.Text = ((trackBar2.Value * (9.0 / 5.0)) + 32).ToString();
        }


How to make programmable thermometer by  C# | Code

Monday, 17 June 2013

How to calculate your GPA with simple application C#

  This is simplest GPA calculator in which user input the previous CGPA and previous Credit Hours (not for first semester these two fields) and no of new subjects and then enters the grade and credit hours of the subjects and insert in data grid view one by one if he by mistake put the wrong Grade or Credit Hours they can delete the wrong input by selecting the row and input again after input all Grades and Credit Hours then click on calculate button calculator calculate the new GPA and CGPA and display it.
Calculation code is:-
//to calculate GPA
            float Gradepoint = 0;
            int k = 0;
            //for read data from datagridview
            for (int i = 0; i < l - 1; i++)
            {
                //grade is A then CH * 4
                if (dataGridView1.Rows[i].Cells[1].Value.ToString() == "A")
 Gradepoint += 4 * float.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString());
                //grade is B+ then CH * 3.5
                else if (dataGridView1.Rows[i].Cells[1].Value.ToString() == "B+")
Gradepoint += 7 * float.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString()) / 2;
                //grade is B then CH * 3
                else if (dataGridView1.Rows[i].Cells[1].Value.ToString() == "B")
Gradepoint += 3 * float.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString());
                //grade is C+ then CH * 2.5
                else if (dataGridView1.Rows[i].Cells[1].Value.ToString() == "C+")
Gradepoint += 5 * float.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString()) / 2;
                //grade is C then CH * 2
                else if (dataGridView1.Rows[i].Cells[1].Value.ToString() == "C")
Gradepoint += 2 * float.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString());
                //grade is D then CH * 1.5
                else if (dataGridView1.Rows[i].Cells[1].Value.ToString() == "D")
Gradepoint += 3 * float.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString()) / 2;
                //adding total CH in k
                k += int.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString());
            }
            //calculate the GPA and displaying maskedtextbox
            maskedTextBox5.Text = ((Gradepoint / k).ToString());
            //to calculate CGPA
            if (maskedTextBox1.Text == "" || maskedTextBox2.Text == "")
                maskedTextBox6.Text = maskedTextBox5.Text;
            else
            {
float h = float.Parse(maskedTextBox1.Text) * (int.Parse(maskedTextBox2.Text));
                h += Gradepoint;
                int CH = int.Parse(maskedTextBox2.Text) + k;
                maskedTextBox6.Text = (h / CH).ToString();
            }
Delete the selected Row code is:-
DialogResult Result = MessageBox.Show("Do You really want to Delete???",      "Confirmation", MessageBoxButtons.YesNo);
            if (Result == DialogResult.Yes)
            {
                dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
                l--;
                label4.Text = "Grade of Subject ";
                label5.Text = "C H of Subject ";
                if (l <= k)
                {
                    label4.Text += l;
                    label5.Text += l;
                }
            }
If the user want to find the new GPA or CGPA then click on New button the New button reset all the field.
Code of New button:-
            dataGridView1.Rows.Clear();
            l = 1;
            k = 0;
            g = 0;
            label4.Text = "Grade of Subject ";
            label5.Text = "C H of Subject ";
            maskedTextBox3.ReadOnly = false;
            maskedTextBox1.Text = "";
            maskedTextBox2.Text = "";
            maskedTextBox3.Text = "";
            maskedTextBox5.Text = "";
            maskedTextBox6.Text = "";
            comboBox1.Text = "";
            comboBox2.Text = "";
            button2.Enabled = false;
            button1.Enabled = false;


Screen Shot

How to calculate your GPA with simple application C#

Sunday, 16 June 2013

How to make Simple Tic Tac Toe Game in C# windows application

How to make Simple Tic Tac Toe Game in C# windows application

This is simple Tic Tac Toe game in C# windows application in which we use 10 buttons, 9 buttons for game the text of these buttons by default null, and 1 for Reset.

The code of reset function is:

 public void reset()
               {
                     button1.Text = button2.Text =
                     button3.Text = button4.Text =
                     button5.Text = button6.Text =
                     button7.Text = button8.Text =
                     button9.Text = "";
                     i = 0;
                }

When we click on any button program first check the 2 conditions first the text of button is null and the how many times buttons are clicked.

  if (i < 9 && button1.Text == "")

Then check the value of (i) if the value of (i) is even then button text change into (X) else (O) and increase the value of (i).

  if (i % 2 == 0)
                    button1.Text = "X";
                else
                    button1.Text = "O";
                i++;

Then check the text of buttons in row, column or diagonal if the text of row, column or diagonal match then the text of team won the game and call the reset function.

  if (button2.Text == text && button3.Text == text)
                {
                    MessageBox.Show("Team " + text + " Won the Game");
                    reset();
                }
                else if (button4.Text == text && button7.Text == text)
                {
                    MessageBox.Show("Team " + text + " Won the Game");
                    reset();
                }

If the value of i=9 and text of any row, column or diagonal is not same then program display the message no one won the game.

  else if (i == 9)
                {
                    MessageBox.Show("No one Won the Game");
                    reset();
                }


Like this we code for all 9 buttons and enjoy the game.
Screen Shot
You can make easily a  tic tac toe game c#


You can make easily a  tic tac toe game c#

                                                                                               Assad Raza 
Visit :http://bel4solutions.com/

Saturday, 15 June 2013

How to make notepad in 5 minutes

How to make notepad in 5 minutes

Now today i will share with you Notepad (text editor ) .
Last time we shared speed test application . I design my notepad on C# . There are several different ideas but i was not sure what i wanted to do . Then i picked one of my design .
I thought it was the more effective one .

Innovative text editor is a sophisticated text editor for editing your data. It allows you to type your text and edit it using our wonderful color palette and tremendous range of font size with an extra feature of saving your files in .txt , .rtf or .doc format.Start typing your precious data using our editor and save it for further usage.

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

namespace TextEditor
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Title = "Save Your Work";
            saveFileDialog1.Filter = "Rich Text File (*.rtf)|*.rtf|Word Document (*.doc)|*.doc|All Files (*.*)|*.*";
            saveFileDialog1.OverwritePrompt = true;
            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.RichText);
            }
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.Title = "Open Your Work";
            openFileDialog1.Filter = "Rich Text File (*.rtf)|*.rtf|Word Document (*.doc)|*.doc|All Files (*.*)|*.*";
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                richTextBox1.LoadFile(openFileDialog1.FileName);
            }
        }

        private void fontToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (fontDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                richTextBox1.Font = (fontDialog1.Font);
            }
        }

        private void colourToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                richTextBox1.ForeColor = (colorDialog1.Color);
            }
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult Result = MessageBox.Show("Do You really want to Close???", "Confirmation", MessageBoxButtons.YesNo);
            if (Result == DialogResult.No)
            {
                e.Cancel = true;
            }
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }

}

Screen Shot



How to make notepad in 5 minutes




How to make notepad in 5 minutes


How to make notepad in 5 minutes





Thursday, 13 June 2013

How to make Typing Speed Tester in C#

How to make Typing Speed Tester in C#

Typing Speed Tester is an exciting game where you can test your typing skills.By using this you can find your words per minute speed and it will provide you filtered result of your correct, incorrect and untype words .It will provide you 100% accurate result free of any error.You can practice daily and can improve your speed.Share it with your friends and compare your results with them.Now Let’s start the journey and see how fast you can type?

Code

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

namespace TypingSpeed
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string[] data;
        private void Form1_Load(object sender, EventArgs e)
        {
            textBox2.Text = "When the test first starts up, it will present you with a choice of lesson and time. If you are in a hurry, choose the 1 Minute Timed Typing Test. For a more accurate assessment, choose the 5 Minute Test. Lessons 26-35 are the classic story lessons and can make a better overall assessment by typing natural sentences. All the other lessons are available, so if you want to see what your wpm is on the home row keys, or your speed in the 10-key you can. New lessons 38 through 40 include Spanish, French and German words. Lessons 36 and 37 are commonly misspelled words. Our words per minute calculation is based on two factors. The first is the number of characters typed in a given time. Words per minute is determined by the standard calculation of 5 characters per word. ";
            string input = textBox2.Text;
            data = input.Split(' ');
            button1.Focus();
        }

        private static int g = 0;
     
        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            textBox1.Text = "";
            textBox1.ReadOnly = false;
            textBox1.Focus();
            textBox3.Text = "";
            label1.Text = "No of Right Words: ";
            label6.Text = "No of Wrong Words: ";
            label3.Text = "No of Untype Words: ";
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            g++;
            label8.Text = g.ToString();
            if (g > 59)
            {
                int i = 0;
                int k = 0;
                string output = textBox1.Text;
                string[] str = output.Split(' ');
                for (int j = 0; j < str.Length; j++)
                {
                    if (str[j] == data[j])
                        i++;
                    else if (str[j] != data[j])
                        k++;
                }
                label1.Text += i.ToString();
                label6.Text += k.ToString();
                textBox3.Text = i.ToString();
                label3.Text += (data.Length - str.Length).ToString();
                textBox1.ReadOnly = true;
                button1.Focus();
                timer1.Enabled = false;
                g = 0;
            }
        }
    }

}


Screen Shot

How to make Typing Speed Tester in C#

How to make Simple Phone Book

How to make Simple Phone Book



Code

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

namespace PhoneBook
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" && textBox2.Text == "" && maskedTextBox1.Text.Length < 11)
                MessageBox.Show("Enter Data in all fields");
            else
            {
                dataGridView1.Rows.Add(textBox1.Text, textBox2.Text, maskedTextBox1.Text);
                textBox1.Text = "";
                textBox2.Text = "";
                maskedTextBox1.Text = "";
                textBox1.Focus();
            }
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            textBox3.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            textBox4.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
            maskedTextBox2.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            DialogResult Result = MessageBox.Show("Do you really want to Delete???", "Confirmation", MessageBoxButtons.YesNo);
            if (Result == DialogResult.Yes)
            {
                dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox3.Text == "" && textBox4.Text == "" && maskedTextBox2.Text.Length < 11)
                MessageBox.Show("Enter Data in all fields");
            else
            {
                dataGridView1.SelectedRows[0].Cells[0].Value = textBox3.Text;
                dataGridView1.SelectedRows[0].Cells[1].Value = textBox4.Text;
                dataGridView1.SelectedRows[0].Cells[2].Value = maskedTextBox2.Text;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }

}


Screen Shot

How to make Simple Phone Book

Wednesday, 12 June 2013

How to make Hospital Management System| Project

How to make Hospital Management System | Project

Screen Shot
                                       

How to make hospital management system | Project                                       


How to make hospital management system | Project




How to make hospital management system | Project



How to make hospital management system | Project


Visit :http://bel4solutions.com/