VS - Assignment - 2
VS - Assignment - 2
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);
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 :
}
if (comboBox2.SelectedItem.ToString() == "Rajasthan") ;
{
comboBox1.Items.Clear();
comboBox1.Items.Add("Jaipur");
comboBox1.Items.Add("Udaipur");
}
{
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 :
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;
ChildForm.WindowState = FormWindowState.Maximized;
ChildForm.WindowState = FormWindowState.Minimized;
ChildForm.WindowState = FormWindowState.Normal;
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 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();
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;