Tuesday 28 May 2013

C# Addition , Multiplication , Subtraction and Division


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 add
{
    public partial class Form1 : Form
    {

        public int a, b;
        int result;
        public Form1()
        {
            InitializeComponent();
            this.MaximizeBox = false;
            this.MinimizeBox = false;

           

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        public void str()
        {
            a = Convert.ToInt16(textBox1.Text);
            b = Convert.ToInt16(textBox2.Text);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            str();
            result=a+b;
           
            MessageBox.Show(Convert.ToString(result));
        }

        private void button2_Click(object sender, EventArgs e)
        {
            str();
            result = a - b;

            MessageBox.Show(Convert.ToString(result));
        }

        private void button3_Click(object sender, EventArgs e)
        {
            str();
            result = a * b;

            MessageBox.Show(Convert.ToString(result));
        }

        private void button4_Click(object sender, EventArgs e)
        {
            str();
            result = a / b;

            MessageBox.Show(Convert.ToString(result));
        }
    }
}


//output


C# List Box Insert,Edit,Delete,Clear All

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 listbox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void addButton_Click(object sender, EventArgs e)
        {
            displayListBox.Items.Add(inputTextbox.Text);
            inputTextbox.Clear();
        }

        private void RemoveBtn_Click(object sender, EventArgs e)
        {
            if (displayListBox.SelectedIndex != -1)
                displayListBox.Items.RemoveAt(
                displayListBox.SelectedIndex);
        }

        private void ClearBtn_Click(object sender, EventArgs e)
        {
            displayListBox.Items.Clear();
        }

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

// output


C# If enter Pressed then data save and leave to another text box to get input



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

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

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode.Equals(Keys.Enter))
{
SendKeys.Send("{TAB}");
}

}

private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode.Equals(Keys.Enter))
{
SendKeys.Send("{TAB}");
}
}
}
}

C# If Esc Pressed Form Closed

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 esc
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Close();
            }
        }
    }
}

Monday 27 May 2013

C# Basic Knowledge Of Masked Text Box



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

namespace maskedtextbox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.MaximizeBox = false;
            this.MinimizeBox = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label1.Visible = true;
            try
            {

                if (maskedTextBox1.Text != "") { label1.Text = maskedTextBox1.Text; }
            }
            catch (Exception ie)
            {
                MessageBox.Show(Convert.ToString(ie));
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            MessageBox.Show("Contact me at twitter: @umarjavedmalik", "Contact us",MessageBoxButtons.OK,MessageBoxIcon.Question);
        }
    }
}
//output then you will be display interface to enter values
//Output by clicking the button ok you will be showed as under then u click help button u will be showed messagebox



Wednesday 22 May 2013

C# All Concepts required in form applications



Massked text Box
If(e.keycode == keys.Enter)
MessageBox.Show(“Hello hello”);
If(e.keycode == key.A)
MessageBox.Show(“you have pressed A”);

For clear
dialogResult abc = messagebox.show(“are you sure you want to clear”,”warning”,MessageBoxButtons,YESNo);
if(abc == system.Windows.Forms.DialogResult.Yes)
txtName.Text = txtUniv.Text = txtNIC.Text = “”;
else
MessageBox.Show(“values not Cleared”);

numMeric up down
value = 100
increment 1
through code

in form_Load
numericupdown.Maximum = 15;
numericupdown.Minumum= -5;
numeric up down incement = 2;
numeric up down value =3;

if press esc form is closed;
then we make button close form
and set text btnkillform
eniveroment.Exit();
1 way
in properties there is cancel button where we slect close button
if there is no button

then we declare an event key down
then
if(e.keycode == keys.Escape)
this.close();
way is to  copy this code in all the buttons of text boxes so we can terminate when press escape

how enter key works
if press enter key then show input works

click on form go to accept button then we go to showinputbutton in properties

picturebox

when I press button then image will be showed
I go to form1_load an write
pictureBox1.Visible = true;

how put image in button
then we go to google
accept button in search
then we choose button image then view original image then save it
close the form and then
go to desin then remove text from button image will be clear then go to properties of button then
select back ground image accept button then select stretched then its awesome works
and then we place icon buttons

then combo box
also called drp[ down list
go to properties then go to items and then write
apple pine orange
then I want if I run the option must show
drop down style is drop down list
what I want if I select the and choose button butt press show item is selected.
Messagebox.show(Comboxbox1.Text);
Show respectively

Then I want from code then form1_load
And set autmaticall selected index 2
Comboxbox1.SelectedIndex =2;

List items
Liost box just like combox box items place items
And wirte in form1_load
Listbox.Selectedindex = 2;
In btn show
Messagebox.Show(listbox1.Text);

C# hotel menu using Radio Button and Check Boxes




 
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 hotel_menu
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
         
          
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            MessageBox.Show("Tea Price is 20 Rupees");
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            MessageBox.Show("Pizza Price is Rs 500");
        }

        private void button1_Click(object sender, EventArgs e)
        {
           int x=0;
           if (checkBox2.Checked == true)
            {
                x += 60;
            }
            if (checkBox3.Checked == true)
            {
                x += 20;
            }
            if (checkBox4.Checked == true)
            {
                x += 600;
            }
            button1.Text = x.ToString();
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            MessageBox.Show("sandwitch is choosed");
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            MessageBox.Show("Tea is Choosed");
        }

        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            MessageBox.Show("Pizza is Choosed");
        }




    }
}



C# how to use Radio Button in Form application










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 march_19pt2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            rdoMale.Checked = true;
            rdoFemale.Checked = true;


        }
        private void btnExit_Click(object sender, EventArgs e)
        {
              string output;
        //Frist if else determining gender
         if(rdoMale.Checked==true)

         output = "male checked";
          else
                output = "Female checked";
                //second if else determining age
                if(rdoAbover20.Checked == true)
                    output+= " and age is greaater than 20";
                    else
                    output += "and age is below 20";
                MessageBox.Show(output);
        }
        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            btnExit_Click(this , e);
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            btnExit_Click(this, e);
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            btnExit_Click(this, e);
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            btnExit_Click(this, e);
        }

        private void btnExit_Click_1(object sender, EventArgs e)
        {

        }

      
    }
}

C# How to use ComboBox in C#




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 box
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            comboBox1.Items.Add("bashir ahmed khan");
            comboBox1.Items.Add("umar javed");
        }

        private void cmdSet_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0)
            {
                textBox1.Text = "bashir ahmed khan";
            }
            if (comboBox1.SelectedIndex == 1)
            {
                textBox1.Text = "Umarjaved";
            }
        }
    }
}

C# Hotel Menu Windows form application

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 bb
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            comboBox1.Items.Add("Pizza");
            comboBox1.Items.Add("bread");
            comboBox1.Items.Add("cake");
            comboBox1.Items.Add("All");

        }

        private void button1_Click(object sender, EventArgs e)
        {
            int x = 0;
            if (comboBox1.SelectedIndex == 0)
            {
                MessageBox.Show("pizza","Correct option is choosed");
            if (checkBox1.Checked == true)
            {
                x += 500;
          
            }
            checkBox2.Visible = false;
            checkBox3.Visible = false;
            if (checkBox2.Checked == true)
            {
                MessageBox.Show("Please choose Another one","Wrong Options");

            } if (checkBox3.Checked == true)
            {
                MessageBox.Show("Please choose Another one", "Wrong Options");

            }

            }


            if (comboBox1.SelectedIndex == 1)
            {
                if (checkBox1.Checked == true)
                {
                    MessageBox.Show("Please choose Another one", "Wrong Options");
                    checkBox1.Visible = false;
                }
            
                if (checkBox2.Checked == true)
                {
                    MessageBox.Show("bread is choosed");
                    x += 40;

                }
              
                if (checkBox3.Checked == true)
                {
                    checkBox3.Visible = false;
                    MessageBox.Show("Please choose Another one", "Wrong Options");

                }
            }
            if (comboBox1.SelectedIndex == 2)
            {
                if (checkBox1.Checked == true)
                {
                    MessageBox.Show("Please choose Another one", "Wrong Options");

                }
                if (checkBox2.Checked == true)
                {
                    MessageBox.Show("Please choose Another one", "Wrong Options");

                }
                if (checkBox3.Checked == true)
                {
                    MessageBox.Show("Cake is choosed");
                    x += 300;

                }
            }
            if (comboBox1.SelectedIndex == 3)
            {
                if (checkBox1.Checked == true)
                {

                    x += 500;
                }
                if (checkBox2.Checked == true)
                {
                    x += 40;

                }
                if (checkBox3.Checked == true)
                {
                 
                    x += 300;

                }
            }


            textBox1.Text = x.ToString();
        }
     
    }
}


C# Read From file using Form Application





save the project in name of the read file

1 include the handler of the using System.IO
2 create the buttons in the form respectively as in code
3 stream reader also include
4 save the file in the bin folder debugg of name phone.Text thnx
5 phone.txt must contains name and phone numbers
run the code and enjoy.....!!



//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;
using System.IO;

namespace ReadFile
{
    public partial class Form1 : Form
    {
        private StreamReader phoneStreamReader;

        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            phoneStreamReader.Close();
            this.Close();
        }

        private void DisplayRecord()
        {
            // read and display the next record
            if (phoneStreamReader.Peek() != -1)
            {
                NameTextBox.Text = phoneStreamReader.ReadLine();
                PhoneTextBox.Text = phoneStreamReader.ReadLine();
            }
            else
                MessageBox.Show("Please try again");


        }

        private void button1_Click(object sender, EventArgs e)
        {
            //read the next record
            DisplayRecord();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //open the file and display the first record

            try
            {
                phoneStreamReader = new StreamReader("Phone.txt");
                DisplayRecord();
            }
            catch
            {
                //file is not found
                MessageBox.Show("File does not exsist.");
            }
        }

    }
}

C# how to make the starting eg Splash screen Form application


/*Instructions go to program.cs file then add this form which u want to introduce as the splash screen then
from gernal tools select the timer and add to form application then you have to enable the timmer property then interval to 5000 for to run it and to disable the maximize bar minimize bar etch upward bar u have to false control box */


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 save
{
    public partial class splshScrn : Form
    {
        public splshScrn()
        {
         
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}


C# Save information using filing

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;
using System.IO;


namespace save
{
    public partial class Form1 : Form
    {
        //class level variables
        string[] phoneData = new string[10];
        int indexInteger;

        public Form1()
        {
            InitializeComponent();
        }

        private void fileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //write to the file
            File.WriteAllLines("TextFile.txt", phoneData);
        }

        private void addButton_Click(object sender, EventArgs e)
        {
            //add to the array
            phoneData[indexInteger++] = nameTextBox.Text;
            phoneData[indexInteger++] = phoneTextBox.Text;

            // clear the fields for the next record
            phoneTextBox.Clear();
            nameTextBox.Clear();
            nameTextBox.Focus();
        }

       

    }
}

C# Shpping Card Preview for Starter of Shopping Cart


C# login Form Code

write this please thnx
//C# body

void button_click()
{

if(textbox1.Text == "umar" && textbox2.Text=="umar"){ Application aApplication = new Application();
aApplication.ShowDialog();}
else
{MessageBox.Show("Wrong password!,ProgramClosing");
this.Close;}
}
//C# body close



C# how show Date and time in form application

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 userControlClock
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void clockTimer_Tick(object sender, EventArgs e)
        {
            displayLabel.Text = DateTime.Now.ToLongTimeString();
            displayLabel2.Text = DateTime.Now.ToLongDateString();
        }
    }
}

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;
using System.Data.SqlClient;

namespace myhelp
{
    public partial class Form1 : Form
    {
        int ctr;
        int jk;
        public Form1()
        {
            InitializeComponent();
            ctr = 0;
                    }
        private void button1_Click(object sender, EventArgs e)
        {
          

        }

        private void button2_Click(object sender, EventArgs e)
        {
          
        }


      
        private void button3_Click(object sender, EventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void button3_Click_1(object sender, EventArgs e)
        {
           
        }
        //insert procedure
        private void button1_Click_1(object sender, EventArgs e)
        {
            SqlConnection cn = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=\"c:\\users\\connecting people\\documents\\visual studio 2012\\Projects\\myhelp\\hell.mdf\";Integrated Security=True;Connect Timeout=30");

            cn.Open();
            if (cn.State == ConnectionState.Open)
            {
                SqlCommand insertCommand = new SqlCommand("insert into hell values('" + textBox1.Text + "','" + textBox2.Text + "')", cn);
                insertCommand.ExecuteNonQuery();
                textBox1.Text = textBox2.Text = "";
                textBox1.Focus();
            }
            else
            {
                MessageBox.Show("Connection is not open");
            }
        }
        //read procedure in text boxes
        private void button2_Click_1(object sender, EventArgs e)
        {
            SqlConnection cn = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=\"c:\\users\\connecting people\\documents\\visual studio 2012\\Projects\\myhelp\\hell.mdf\";Integrated Security=True;Connect Timeout=30");
            cn.Open();
            SqlCommand myReadCommand = new SqlCommand("select * from hell", cn);
            SqlDataAdapter da = new SqlDataAdapter(myReadCommand);
            DataSet ds = new DataSet();
            da.Fill(ds);
            MessageBox.Show("Total rows:" + ds.Tables[0].Rows.Count.ToString());
            textBox1.Text = ds.Tables[0].Rows[ctr][0].ToString();
            textBox2.Text = ds.Tables[0].Rows[ctr][1].ToString();
            ctr++;
            cn.Close();
        }
        //data grid view display procedure
        private void button3_Click_2(object sender, EventArgs e)
        {
            SqlConnection cn = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=\"c:\\users\\connecting people\\documents\\visual studio 2012\\Projects\\myhelp\\hell.mdf\";Integrated Security=True;Connect Timeout=30");
            cn.Open();
            SqlCommand myReadCommand = new SqlCommand("select * from hell", cn);
            SqlDataAdapter da = new SqlDataAdapter(myReadCommand);
            DataSet ds = new DataSet();
            da.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];
        }
        //delete all record procedure
        private void button4_Click(object sender, EventArgs e)
        {
           
           //delete specific id
              /*  string connectionString =("Data Source=(LocalDB)\\v11.0;AttachDbFilename=\"c:\\users\\connecting people\\documents\\visual studio 2012\\Projects\\myhelp\\hell.mdf\";Integrated Security=True;Connect Timeout=30");
                using (SqlConnection conn =
                    new SqlConnection(connectionString))
                {
                    conn.Open();
                    using (SqlCommand cmd =
                        new SqlCommand("DELETE FROM hell " +
                            "WHERE Id=@Id", conn))
                    {
                        cmd.Parameters.AddWithValue("@Id",'2');

                        int rows = cmd.ExecuteNonQuery();

                        //rows number of record got deleted
                    }
                }*/
         
          
            SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=\"c:\\users\\connecting people\\documents\\visual studio 2012\\Projects\\myhelp\\hell.mdf\";Integrated Security=True;Connect Timeout=30");
           SqlCommand cmd = new SqlCommand();
           cmd.CommandText = "DELETE FROM hell WHERE Id=Id";
            cmd.Connection = con;
            con.Open();
            int numberDeleted = cmd.ExecuteNonQuery();
            //Response.Write(numberDeleted.ToString() + " employees were deleted.<br>");
            // use this instead of the above line if we're in a windows form rather than an ASP.NET page
            MessageBox.Show(numberDeleted.ToString() + " employees were deleted.<br>");
            con.Close();

        
        }
        //delete by id procedure
        private void button5_Click(object sender, EventArgs e)
        {
            jk = Convert.ToInt32(textBox3.Text);
            SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=\"c:\\users\\connecting people\\documents\\visual studio 2012\\Projects\\myhelp\\hell.mdf\";Integrated Security=True;Connect Timeout=30");
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "delete from hell where id='" + textBox3.Text + "'";
            cmd.Connection = con;
            con.Open();
            int numberDeleted = cmd.ExecuteNonQuery();

            con.Close();
            MessageBox.Show("Record is deleted", "Programming at kastrak");
        }

        //refresh procedure
        private void button6_Click(object sender, EventArgs e)
        {
            SqlConnection cn = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=\"c:\\users\\connecting people\\documents\\visual studio 2012\\Projects\\myhelp\\hell.mdf\";Integrated Security=True;Connect Timeout=30");
            cn.Open();
            SqlCommand myReadCommand = new SqlCommand("select * from hell", cn);
            SqlDataAdapter da = new SqlDataAdapter(myReadCommand);
            DataSet ds = new DataSet();
            da.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];
        }

   
        }
   
}

C sharp


C# How To Pick date and time and save to form application

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 DatePicker
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            DateTime dropOffDate = dateTimePicker1.Value;

            if (dropOffDate.DayOfWeek == DayOfWeek.Friday || dropOffDate.DayOfWeek == DayOfWeek.Saturday || dropOffDate.DayOfWeek == DayOfWeek.Sunday)

                outputLabel.Text = dropOffDate.AddDays(3).ToLongDateString();

            else
                outputLabel.Text = dropOffDate.AddDays(2).ToLongDateString();


        }

        private void Form1_Load(object sender, EventArgs e)
        {
            dateTimePicker1.MinDate = DateTime.Today;

            dateTimePicker1.MaxDate = DateTime.Today.AddYears(1);
        }


    }
}