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




    }
}