8/3/2019 Visual Programming Assignmnt
http://slidepdf.com/reader/full/visual-programming-assignmnt 1/15
VisualProgrammi
ng
September 5
2011Submitted by: Rishabh SainiI.T.3-B,Reg No.:1080920052 Assignment
8/3/2019 Visual Programming Assignmnt
http://slidepdf.com/reader/full/visual-programming-assignmnt 2/15
Program 1: Develop a console application to explain
hierarchical inheritance
Solution:
using System;using System.Collections.Generic;using System.Linq;using System.Text;
namespace Assignmentprog1{ class Program
{ static void Main(string[] args)
{ ashok t = new ashok();
t.print1();t.print2();t.show();
honda c = new honda();c.show1();c.show2();c.show();
}
} class vehicle
{ public void show()
{ Console.WriteLine("I am the Biggest and the heaviest");
}}
class car : vehicle{
public void show1(){
Console.WriteLine("I m a small running home of all humans");}
}
class truck : vehicle{
public void print1(){
Console.WriteLine("all big transporters use me");}
} class honda : car
{ public void show2()
{ Console.WriteLine("My best IS HONDA CIVIC");
}
} class ashok : truck
{ public void print2()
{ Console.WriteLine("I make big vehicles in India");
8/3/2019 Visual Programming Assignmnt
http://slidepdf.com/reader/full/visual-programming-assignmnt 3/15
Console.ReadLine();}
}
}
Output:
Program 2: Develop a windows application to form a
calculator which performs all arithmetic operations.
Solution:
Properties:Control PropertyName
Label1 First num
Label2 Second num
Label3 Result
Label4 result
8/3/2019 Visual Programming Assignmnt
http://slidepdf.com/reader/full/visual-programming-assignmnt 4/15
Radiobutton 1 Add
Radiobutton2 Subtract
Radiobutton3 Multiply
Radiobutton4 Divide
Button1 Do
Button2 Clear
Coding:
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 WindowsFormsApplication2{ public partial class Form1 : Form
{ public Form1(){
InitializeComponent();}
private void textBox1_TextChanged(object sender, EventArgs e){
}
private void textBox2_TextChanged(object sender, EventArgs e){
}
private void textBox3_TextChanged(object sender, EventArgs e){
}
private void radioButton1_CheckedChanged(object sender, EventArgs e){
}
private void radioButton2_CheckedChanged(object sender, EventArgs e){
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
8/3/2019 Visual Programming Assignmnt
http://slidepdf.com/reader/full/visual-programming-assignmnt 5/15
{
}
private void radioButton4_CheckedChanged(object sender, EventArgs e){
}
private void button2_Click(object sender, EventArgs e){
if (radioButton1.Checked==true){
int a, b, c;a = Convert.ToInt16(textBox1.Text);b = Convert.ToInt16(textBox2.Text);c = a + b;label4.Text = Convert.ToString(c);
} if (radioButton2.Checked==true)
{
int a, b, c;a = Convert.ToInt16(textBox1.Text);b = Convert.ToInt16(textBox2.Text);c = a - b;label4.Text = Convert.ToString(c);
}
if (radioButton3.Checked==true){
int a, b, c;a = Convert.ToInt16(textBox1.Text);b = Convert.ToInt16(textBox2.Text);c = a * b;label4.Text = Convert.ToString(c);
}
if (radioButton4.Checked==true){
int a, b, c;a = Convert.ToInt16(textBox1.Text);b = Convert.ToInt16(textBox2.Text);c = a / b;label4.Text = Convert.ToString(c);
}}
private void button1_Click(object sender, EventArgs e){
textBox1.Text = " ";textBox2.Text = " ";label4.Text = " ";
}}
}
8/3/2019 Visual Programming Assignmnt
http://slidepdf.com/reader/full/visual-programming-assignmnt 6/15
Output:
Program 3:Design a MDI text editor(any child window)application using c# windows application.
Solution:
8/3/2019 Visual Programming Assignmnt
http://slidepdf.com/reader/full/visual-programming-assignmnt 7/15
Coding:
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 WindowsFormsApplication1{ public partial class Form1 : Form
{ private int childNumber = 0; public Form1()
{InitializeComponent();
}
private void button1_Click(object sender, EventArgs e){
Form child = new Form();child.MdiParent = this;child.Text = "Harsh" + childNumber++;child.Show();
}}
}
Output:
8/3/2019 Visual Programming Assignmnt
http://slidepdf.com/reader/full/visual-programming-assignmnt 8/15
Problem 4:Design a windows application that illustrate list
control and user defined dialog box for displaying the first
name, last name, job title of the employee in a company.
Write the steps in designing the application withproperties designed.
Solution:
Properties:
Control Property name
Label1 First Name
Label2 Last Name
Label3 Job TitleButton1 Ok
Button2 Cancel
8/3/2019 Visual Programming Assignmnt
http://slidepdf.com/reader/full/visual-programming-assignmnt 9/15
Steps:
1. At first we need a private member to hold the employee
object the dialog is working on.
2.Then we are using the public employee property. So that
Other code use dialog can get the employee data.
Coding:
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 Employee1{ public class employee
{ public string FirstName; public string LastName; public string JobTitle; public override string ToString()
{ return FirstName + " " + LastName + " " + JobTitle;
}};
public partial class Dialog : Form{
public Dialog(){
InitializeComponent();}
private employee _employee = null;
public employee staffMember{
get{
if (_employee == null){
_employee = new employee();
}_employee.FirstName = textBox1.Text;
8/3/2019 Visual Programming Assignmnt
http://slidepdf.com/reader/full/visual-programming-assignmnt 10/15
_employee.LastName = textBox2.Text;_employee.JobTitle = textBox3.Text;
return _employee;}
set{
_employee = value;textBox1.Text = _employee.FirstName;
textBox2.Text = _employee.LastName;textBox3.Text = _employee.JobTitle;
}
}}
}
3. Now double click the Form1.cs in the solution explorer to
bring up the main form in the designer window. Drop
some control onto the form so that it looks like..
8/3/2019 Visual Programming Assignmnt
http://slidepdf.com/reader/full/visual-programming-assignmnt 11/15
Properties:
Control Property Name
List Box Employee ListLabel1 firstName
Label2 LastName
Label3 JobTitle
Button1 Add
Button2 Edit
Button3 Delete
4.The Code is written to add new item to the list box.
Double click the add button to drag into its click event
Handler. All we need to do here is show the dialog and
then add the new employee object,it creates into the
list box.
Coding:
using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;
namespace Employee1{
public partial class Form1 : Form{
public Form1()
8/3/2019 Visual Programming Assignmnt
http://slidepdf.com/reader/full/visual-programming-assignmnt 12/15
{InitializeComponent();
}
private void button1_Click(object sender, EventArgs e){
dialog newEmployeeDialog = new dialog(); if (newEmployeeDialog.ShowDialog()==dialogResult.OK)
{ listBox1.Items.Add(newEmployeeDialog.staffMember);}
}
private void button3_Click(object sender, EventArgs e){
if (listBox1.SelectedIndex == -1) return; if (MessageBox.Show("Really Delete", "Delete", MessageBoxButtons.YesNo,MessageBoxIcon.Question) == dialogResult.Yes)
{listBox1.Items.Remove(listBox1.SelectedItem);
}
}
private void button2_Click(object sender, EventArgs e){
if (listBox1.SelectedIndex == -1) return; int employeeNum = listBox1.SelectedIndex; dialog newEmployeeDialog = new dialog();
newEmployeeDialog.staffMember = (employee)listBox1.SelectedItem; if (newEmployeeDialog.ShowDialog()==dialogResult.OK)
{listBox1.Items.RemoveAt(employeeNum);listBox1.Items.Insert(employeeNum, newEmployeeDialog.staffMember);listBox1.SelectedIndex = employeeNum;
}
}
private void listBox1_SelectedIndexChanged( object sender, EventArgs e){
if (listBox1.SelectedIndex!=-1)
{ employee currentEmployee=(employee)listBox1.SelectedItem;
textBox1.Text = currentEmployee.FirstName;textBox2.Text=currentEmployee.LastName;textBox3.Text = currentEmployee.JobTitle;
} else
{textBox1.Text=textBox2.Text=textBox3.Text= "";
}}
private void Form1_Load(object sender, EventArgs e){
}
}
8/3/2019 Visual Programming Assignmnt
http://slidepdf.com/reader/full/visual-programming-assignmnt 13/15
}
OutPut:
Program 5: Design a windows application to illustrate tree
view control to list out odd and even number. Also design
to add, image, colour, etc.
Solution:
8/3/2019 Visual Programming Assignmnt
http://slidepdf.com/reader/full/visual-programming-assignmnt 14/15
Steps:
1. Open a new form and drag button1 called load.
2.Drag tree view from toolbox.
3.Double click on load button and write the coding.
Coding:
using System.Data;using System.Drawing;
using System.Linq;using System.Text;using System.Windows.Forms;
namespace treeview{ public partial class Form1 : Form
{ public Form1()
{InitializeComponent();
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e){
}
8/3/2019 Visual Programming Assignmnt
http://slidepdf.com/reader/full/visual-programming-assignmnt 15/15
private void button1_Click(object sender, EventArgs e){
treeView1.Nodes.Clear();treeView1.ShowNodeToolTips = true;
TreeNode evenNumbers = treeView1.Nodes.Add("even numbers"); TreeNode oddNumbers = treeView1.Nodes.Add("odd numbers"); /* TreeNode evenNumbers = treeView1.Nodes.Add("even", "even numbers", 0, 1);
TreeNode oddNumbers = treeView1.Nodes.Add("odd", "odd numbers", 0, 1);*/
evenNumbers.BackColor = Color.Red;evenNumbers.ForeColor = Color.Yellow;evenNumbers.ToolTipText = "the evens";oddNumbers.BackColor = Color.Blue;oddNumbers.ForeColor = Color.Red;oddNumbers.ToolTipText = "the odds";
for (int i = 1; i < 500; i++){
if (i % 2 == 0){
evenNumbers.Nodes.Add(i.ToString());}
else
{ oddNumbers.Nodes.Add(i.ToString());}
}
}}
}
Output:
Top Related