Windows Application Notes

 

Windows Application

 

1.  Message Box

 


 

      

      private void button1_Click(object sender, EventArgs e)

        {

            MessageBox.Show("welcome " +textBox1.Text);

        }

2.  Calculation



private void button1_Click(object sender, EventArgs e)

{

    int a=Convert.ToInt32(textBox1.Text);

    int b = Convert.ToInt32(textBox2.Text);

    int c = a + b;

    textBox3.Text=c.ToString();

    int d = a - b;

    textBox4.Text=d.ToString();

    int f = a * b;

    textBox5.Text=f.ToString();

    int g = a / b;

    textBox6.Text=g.ToString();

}

 

3.  ComboBox

 

 


 

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

        {

            label2.Text = comboBox1.SelectedItem.ToString();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            comboBox1.Items.Add("AI");

            comboBox1.Items.Add("HTML");

            comboBox1.Items.Add("CSS");

        }

4.



      private void button1_Click(object sender, EventArgs e)

      {

              int a = Convert.ToInt32(textBox1.Text);

              int b = Convert.ToInt32(textBox2.Text);

              int c = a + b;

              textBox3.Text = c.ToString();

      }

 

      private void button2_Click(object sender, EventArgs e)

      {

          int a = Convert.ToInt32(textBox1.Text);

          int b = Convert.ToInt32(textBox2.Text);

          int d = a - b;

          textBox3.Text = d.ToString();

      }

      private void button3_Click(object sender, EventArgs e)

      {

          int a = Convert.ToInt32(textBox1.Text);

          int b = Convert.ToInt32(textBox2.Text);

          int f = a * b;

          textBox3.Text = f.ToString();

           

      }

      private void button4_Click(object sender, EventArgs e)

      {

          int a = Convert.ToInt32(textBox1.Text);

          int b = Convert.ToInt32(textBox2.Text);

          int g = a / b;

          textBox3.Text = g.ToString();

      }

  }

5.



 

  private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

  {

      int a=Convert.ToInt32(textBox1.Text);

      int b = Convert.ToInt32(textBox2.Text);

      int c;

      if (comboBox1.SelectedIndex == 0)

      {

          c = a + b;

          textBox3.Text = c.ToString();

      }

      else if (comboBox1.SelectedIndex == 1)

      {

          c = a - b;

          textBox3.Text = c.ToString();

      }

      else if (comboBox1.SelectedIndex == 2)

      {

          c = a * b;

          textBox3.Text = c.ToString();

      }

      else if (comboBox1.SelectedIndex == 3)

      {

          c = a / b;

          textBox3.Text = c.ToString();

      }

      else

          textBox3.Text = "INVALID";

  }

6.List Box



 

 private void button1_Click(object sender, EventArgs e)

 { listBox1.Items.Add("C#");

     listBox1.Items.Add("ASP");

     listBox1.Items.Add("JAVA");

     listBox1.Items.Add("PYTHON");

 }

7.



namespace WindowsFormsApp4

{

    internal static class Program

    {

        /// <summary>

        /// The main entry point for the application.

        /// </summary>

        [STAThread]

        static void Main()

        {

            Application.EnableVisualStyles();

            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(new secondform());

        }

    }

}

private void button2_Click(object sender, EventArgs e)

{

    Form1 form = new Form1();

    this.Hide();

    form.Show();

}

private void button2_Click(object sender, EventArgs e)

 {

     Form1 form = new Form1();

     this.Hide();

     form.Show();

 }

 

8. Color Dialog





    public partial class thirdform : Form

    {

        public thirdform()

        {

            InitializeComponent();

        }

 

        private void button1_Click(object sender, EventArgs e)

        {    

     if(colorDialog1.ShowDialog() == DialogResult.OK)

     {

     this.BackColor = colorDialog1.Color;

      }

        }

    }

}

 

9.

 


         if(colorDialog1.ShowDialog() == DialogResult.OK)

         {

           this.BackColor = colorDialog1.Color;

           button1.BackColor = colorDialog1.Color;

         }

 

     

10. Radio Button                



 

private void button1_Click(object sender, EventArgs e)

{

    int a = Convert.ToInt32(textBox1.Text);

    int b = Convert.ToInt32(textBox2.Text);

    int c;

    if(radioButton1.Checked ==true)

    {

        c = a + b;

        textBox3.Text=c.ToString();

    }

    else if (radioButton2.Checked == true)

    {

        c = a - b;

        textBox3.Text = c.ToString();

    }

    else if (radioButton3.Checked == true)

    {

        c = a * b;

        textBox3.Text = c.ToString();

    }

    else if (radioButton4.Checked == true)

    {

        c = a / b;

        textBox3.Text = c.ToString();

    }

}

 

11. TreeView

Eg1:


  

   private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)

    {

        TreeNode node = treeView1.SelectedNode;

        MessageBox.Show(String.Format("you selected:{0}", node.Text));

    }

 

    private void TreeView_Load(object sender, EventArgs e)

    {

        TreeNode treenode = new TreeNode("Windows");

        treeView1.Nodes.Add(treenode);

        treenode = new TreeNode("Linux");

        treeView1.Nodes.Add(treenode);

        TreeNode node2 = new TreeNode("C#");

        TreeNode node3 = new TreeNode("vb.net");

        TreeNode[] array = new TreeNode[] { node2, node3 };

        treenode = new TreeNode("dotnet pearls", array);

        treeView1.Nodes.Add(treenode);

    }

}

 

Eg2:



private void Form2_Load(object sender, EventArgs e)

{

    TreeNode tree = new TreeNode("SQL");

    treeView1.Nodes.Add(tree);

    tree = new TreeNode("PYTON");

    treeView1.Nodes.Add(tree);

    TreeNode tree1 = new TreeNode("ASP.NET");

    TreeNode tree2 = new TreeNode("VB.NET");

    TreeNode[] array1 = new TreeNode[] { tree1, tree2 };

    tree = new TreeNode(".NET", array1);

    treeView1.Nodes.Add(tree);

}

 

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)

{

    TreeNode node = treeView1.SelectedNode;

    textBox1.Text= node.Text;

    //MessageBox.Show(String.Format("you selected:{0}", node.Text));

}

 

12. Stack [Last In First Out]



using System.Collections;

 

public partial class Stackexample : Form

 {

     Stack s=new Stack();

     public Stackexample()

     {

         InitializeComponent();

     }

 

     private void button1_Click(object sender, EventArgs e)

     {

         s.Push(textBox1.Text);

         MessageBox.Show("pushed");

     }

 

     private void button2_Click(object sender, EventArgs e)

     {

         listBox1.Items.Add(s.Pop());

     }

 

13. Queue  [First In First Out]



using System.Collections;

 

namespace WindowsFormsApp4

{

    public partial class QueueExample : Form

    {

        Queue q = new Queue();

        public QueueExample()

        {

            InitializeComponent();

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            q.Enqueue(textBox1.Text);

            MessageBox.Show("Enqueue");

        }

14. Menu Strip




private void queueToolStripMenuItem_Click(object sender, EventArgs e)

 {

     QueueExample queueExample = new QueueExample();

     queueExample.Show();

 }

 

 private void stackToolStripMenuItem_Click(object sender, EventArgs e)

 {

     Stackexample stackexample = new Stackexample();

     stackexample.Show();

 }

 

 private void treeViewToolStripMenuItem_Click(object sender, EventArgs e)

 {

     TreeView treeView = new TreeView();

     treeView.Show();

 }

 

 private void radioButtonToolStripMenuItem_Click(object sender, EventArgs e)

 {

     RadioButton radioButton = new RadioButton();

     radioButton.Show();

 }

 

 private void undoToolStripMenuItem_Click(object sender, EventArgs e)

 {

     richTextBox1.Undo();

 }

 

 private void redoToolStripMenuItem_Click(object sender, EventArgs e)

 {

     richTextBox1.Redo();

 }

 private void cutToolStripMenuItem_Click(object sender, EventArgs e)

 {

     richTextBox1.Cut();

 }

 

 private void copyToolStripMenuItem_Click(object sender, EventArgs e)

 {

     richTextBox1.Copy();

 }

 

 private void pasteToolStripMenuItem_Click(object sender, EventArgs e)

 {

     richTextBox1.Paste();

 }

 

 private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)

 {

     richTextBox1.SelectAll();

 }

 

 private void dateTimeToolStripMenuItem_Click(object sender, EventArgs e)

 {

     richTextBox1.Text = DateTime.Now.ToString();

 }

 

 private void closeToolStripMenuItem_Click(object sender, EventArgs e)

 {

     Application.Exit();

 }

 

 private void newToolStripMenuItem_Click(object sender, EventArgs e)

 {

     richTextBox1.Clear();

 }

 

 private void foreColorToolStripMenuItem_Click(object sender, EventArgs e)

 {

     if(colorDialog1.ShowDialog() == DialogResult.OK)

     {

         richTextBox1.ForeColor = colorDialog1.Color;

     }

 }

 

 private void backColorToolStripMenuItem_Click(object sender, EventArgs e)

 {

     if(colorDialog1.ShowDialog()==DialogResult.OK)

     {

         richTextBox1.BackColor=colorDialog1.Color;

     }

 }

 

15. Font Dialog

 


 

 

 private void fontToolStripMenuItem1_Click(object sender, EventArgs e)

 {

     if(fontDialog1.ShowDialog()==DialogResult.OK )

     {

         richTextBox1.Font = fontDialog1.Font;

     }

 }

 

 

1. IsmdiCondainer property=true

2. Form border style property=none

 

3. RadioButton rb = new RadioButton();

 rb.MdiParent= this;

 rb.Show();

 



No comments:

Post a Comment

Techzmatrix