0% found this document useful (0 votes)
4 views

Practical -2

Uploaded by

happylifehome924
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Practical -2

Uploaded by

happylifehome924
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Using Lable, TextBox and Button controls

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

private void showbtn_Click(object sender, EventArgs e)


{
//first
// if (this.firsttxt.Text != "")
if(this.firsttxt.Text.Length !=0)
{

// the above code is used for concatenation of string


// now we are going to add the values
int x = Convert.ToInt32(this.firsttxt.Text);
int y = int.Parse(this.secondtxt.Text);
this.resulttxt.Text = (x + y).ToString();
}
}

private void clearbtn_Click(object sender, EventArgs e)


{
//second
this.firsttxt.Text = "";
this.secondtxt.Text = "";
this.resulttxt.Text = "";

// OR
//firsttxt.Clear();
//secondtxt.Clear();
//resulttxt.Clear();
}

private void closebtn_Click(object sender, EventArgs e)


{
// Code for form closing
//this.Close();
// this.Dispose();
Application.Exit();

private void Form1_Load(object sender, EventArgs e)


{
// last step creating dynamic button

Button dynamicbtn = new Button();


dynamicbtn.Width = 90;
dynamicbtn.Height = 30;
dynamicbtn.Text = "Display";
dynamicbtn.Name = "button1";
dynamicbtn.BackColor = Color.Green;
dynamicbtn.ForeColor = Color.Red;
dynamicbtn.Location = new Point(100, 30);
dynamicbtn.Font = new Font("timenewroman", 12,
FontStyle.Italic );
Controls.Add(dynamicbtn);

//Assignment No-1: write down a program to create three buttons


dynamically at run time.

} } }

------------------------------------------------------------------------------------------------------------------------------------------

Adding additional forms to main form


The following figure illustrate the way of adding new form to the existing form

When we want to display the new Form from existing Form write the following code under click envent.

Form2 frm = new Form2();


frm.Show();
---------------------------------------------------------------------------------------------------------------------

Message Box

Write the following code under button click event. This code will reveals different aspects of Message
Box.

private void messagebtn_Click(object sender, EventArgs e)


{
// first step
//MessageBox.Show ("hello");

//second step
// MessageBox.Show("this is seventh semester","Semester",
MessageBoxButtons.YesNo);

// third step
if (MessageBox.Show("information", "semester",
MessageBoxButtons.OKCancel, MessageBoxIcon.Information) ==
DialogResult.OK)
{
// Application.Exit();
this.Close();
}
if (Convert.ToBoolean(DialogResult.No ))
{
MessageBox.Show("please, try again");

}
---------------------------------------------------------------------------------------------------------------------

You might also like