0% found this document useful (0 votes)
7 views10 pages

VS - Assignment - 2

The document outlines a series of programming assignments focused on creating Windows Forms applications using C#. It includes tasks such as designing forms for adding and removing cities from a combo box, managing state selections, transferring items between list boxes, implementing a text pad application with multiple functionalities, and handling file read/write operations for both text and binary files. Each task is accompanied by code snippets demonstrating the required functionality.

Uploaded by

roger88838
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views10 pages

VS - Assignment - 2

The document outlines a series of programming assignments focused on creating Windows Forms applications using C#. It includes tasks such as designing forms for adding and removing cities from a combo box, managing state selections, transferring items between list boxes, implementing a text pad application with multiple functionalities, and handling file read/write operations for both text and binary files. Each task is accompanied by code snippets demonstrating the required functionality.

Uploaded by

roger88838
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Assignment-2

Name : Yash Nanda


Division : A
Roll No. : 86

1. Design a form in that provide facility to user to add city from textbox to
combo box and if city already in combo box than it show particular
message using message. User also remove city dynamically from combo
box.

Answer :

public Form1() { }
private void button1_Click(object sender, EventArgs e)
InitializeComponent();
{

if (comboBox1.Items.Contains(textBox1.Text))
{
MessageBox.Show("city already added...");

}
else
{ }
comboBox1.Items.Add(textBox1.Text);

private void button2_Click(object sender, EventArgs e)


{
MessageBox.Show(comboBox1.SelectedItem + "city remove");
comboBox1.Items.Remove(comboBox1.SelectedItem);
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)


{
MessageBox.Show("you selected" + comboBox1.SelectedItem +
"city...");
}

2. Design form in that take one combobox which contain state name. when user
click on particular state ,state name will be store in list box and if list
already contain that state name then display appropriate message.
Answer :

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)


{
if (comboBox2.SelectedItem.ToString() == "Gujarat") ;
{
comboBox1.Items.Clear();
comboBox1.Items.Add("Ahmedabad");
comboBox1.Items.Add("Baroda");
comboBox1.Items.Add("Surat");

}
if (comboBox2.SelectedItem.ToString() == "Rajasthan") ;
{
comboBox1.Items.Clear();
comboBox1.Items.Add("Jaipur");
comboBox1.Items.Add("Udaipur");
}

private void button1_Click(object sender, EventArgs e)


{
if (comboBox2.SelectedItem.ToString() == "Gujarat")
{
if (listBox1.Items.Contains(comboBox1.SelectedItem.ToString()))

{
MessageBox.Show("This state is already in listbox");
}
}
else
{ }
listBox1.Items.Add(comboBox2.SelectedItem.ToString());

}
}
}
3. Write a program to transfer one or more car name list from first list box to
second list box and from second list box to first.

Answer :

private void button1_Click(object sender, EventArgs e)


{
//>
listBox2.Items.Add(listBox1.SelectedItem);
listBox1.Items.Remove(listBox1.SelectedItem);
}
private void button3_Click(object sender, EventArgs e)
{
//<
listBox1.Items.Add(listBox2.SelectedItem);
listBox2.Items.Remove(listBox2.SelectedItem);
}
private void button2_Click(object sender, EventArgs e)
{
//>>
while (listBox1.SelectedItems.Count > 0)
{
listBox2.Items.Add(listBox1.SelectedItem);
listBox1.Items.Remove(listBox1.SelectedItem);
}
}

private void button4_Click(object sender, EventArgs e)


{
while (listBox2.SelectedItems.Count > 0)
{
listBox1.Items.Add(listBox2.SelectedItem);
listBox2.Items.Remove(listBox2.SelectedItem);
}
}
}
}
4. Implement textpad application using richtextbox.make means like file
(new,close,close all exit),window(maximize,minimize Normal) tile
(Horizontal,vertical,cascade use all common diolog controls and implement
functionalities.
Answer :

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 WindowsFormsApp19
{
public partial class Form1 : Form
{
public Form1()
{ }
int InitializeComponent();
m_ChildFormNumber = 0;
Form ChildForm;

private void newToolStripMenuItem_Click(object sender, EventArgs e)


{
ChildForm = new Form();
ChildForm.MdiParent = this;
m_ChildFormNumber += 1;
ChildForm.Text = "Window" + m_ChildFormNumber;
ChildForm.Show();

private void exitToolStripMenuItem_Click(object sender, EventArgs e)


{ }
Application.Exit();
private void horizontalToolStripMenuItem_Click(object sender, EventArgs e)
{ }
private void verticalToolStripMenuItem_Click(object sender, EventArgs e)
{ }
this.LayoutMdi(MdiLayout.TileHorizontal);
private void cascadeToolStripMenuItem_Click(object sender, EventArgs e)
{ }
private void maximizedToolStripMenuItem_Click(object sender, EventArgs e)
{ }
this.LayoutMdi(MdiLayout.TileVertical);
private void minimizedToolStripMenuItem_Click(object sender, EventArgs e)
{ }
private void normalToolStripMenuItem_Click(object sender, EventArgs e)
{ }
this.LayoutMdi(MdiLayout.Cascade);
private void closeAllToolStripMenuItem_Click(object sender, EventArgs e)
{

ChildForm.WindowState = FormWindowState.Maximized;

ChildForm.WindowState = FormWindowState.Minimized;

ChildForm.WindowState = FormWindowState.Normal;

foreach(Form ChildForm in this.MdiChildren)


{ }
ChildForm.Close();

private void closeToolStripMenuItem_Click(object sender, EventArgs e)


{
ActiveMdiChild.Close();
} }

5. Write a program which provide read and write functionality with text file.

Answer :

public Form1()
{ }
FileStream fs;
InitializeComponent();
StreamReader sr;

StreamWriter sw;

private void Form1_Load(object sender, EventArgs e)


{
}

private void button1_Click(object sender, EventArgs e)


{
fs = new FileStream("Rensi.text", FileMode.Open);
sr = new StreamReader(fs); object ob; ob =
sr.ReadLine(); textBox1.Text = ob.ToString();
sr.Close(); fs.Close();

}
private void button2_Click(object sender, EventArgs e)
{
fs = new FileStream("Rensi.text", FileMode.Create);
sw = new StreamWriter(fs);
object a;

sw.WriteLine(textBox1.Text);
sw.Close();
fs.Close();

private void button3_Click(object sender, EventArgs e)


{ }
textBox1.Clear();
6. Write a program which provide read and write functionality with binary file.

Answer :
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 WindowsFormsApp23
{
public partial class Form1 : Form
{
public Form1()
{ }
FileStream fs;
InitializeComponent();
BinaryReader br;
BinaryWriter bw;

private void button1_Click(object sender, EventArgs e)


{

fs = new FileStream("test.txt", FileMode.Open);


br = new BinaryReader(fs);
object ob;
ob = br.ReadString();
textBox1.Text = ob.ToString();
br.Close();
fs.Close();

private void button2_Click(object sender, EventArgs e)


{
fs = new FileStream("test.txt", FileMode.Open);
bw = new BinaryWriter(fs);
bw.Write(textBox1.Text);
bw.Close();
fs.Close();
}
private void button3_Click(object sender, EventArgs e)
{ }
textBox1.Clear();

You might also like