PROGRAMMING USING C#
LAB MANUAL
SARASWATHI RAMALINGAM
SRI AKILANDESWARI WOMENS COLLEGE
THIRUVALLUVAR UNIVERSITY
Windows Form Controls (List,
Combo, Timer, Group Box,
Picture Box)
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 controls {
public partial class Form1 : Form { private int i;
public Form1()
{ InitializeComponent(); }
private void time1()
{
Timer timer1 = new Timer();
timer1.Interval = 1000;
timer1.Enabled = true;
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();
i = 30;
}
private void listBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
if (listBox1.SelectedItem == "Computer Quiz")
{
groupBox2.Enabled = false;
}
else
{
groupBox2.Enabled = true;
listBox1.Enabled = false;
time1();
}
if (listBox1.SelectedItem == "Maths Quiz")
{
groupBox1.Enabled = false;
}
else
{
groupBox1.Enabled = true;
listBox1.Enabled = false;
time1();
} }
private void button1_Click(object sender, EventArgs e)
{
listBox1.Enabled = true;
if (groupBox1.Enabled == false || groupBox2.Enabled == false)
{
MessageBox.Show("Please Select Quiz Mode");
} }
private void timer1_Tick(object sender, EventArgs e)
{
int result = 0;
if (comboBox1.SelectedItem == "Undo")
{
result = result + 5;
}
if (comboBox2.SelectedItem == "Redo")
{
result = result + 5;
}
if (comboBox3.SelectedItem == "Print Preview")
{
result = result + 5;
}
if (comboBox4.SelectedItem == "Close a Worksheet")
{
result = result + 5;
}
if (comboBox5.SelectedItem == "Insert a Worksheet")
{
result = result + 5;
}
if (comboBox6.SelectedItem == "62")
{
result = result + 5;
}
if (comboBox7.SelectedItem == "11")
{
result = result + 5;
}
if (comboBox8.SelectedItem == "25")
{
result = result + 5;
}
if (comboBox9.SelectedItem == "108")
{
result = result + 5;
}
if (comboBox10.SelectedItem == "1")
{
result = result + 5;
}
if (i >= 0) { i = i - 1; textBox1.Text = i + " Seconds";
}
if (textBox1.Text == 0 + " Seconds")
{
MessageBox.Show("Time Out Your score=" + result);
this.Close();
} }
private void Form1_Load(object sender, EventArgs e)
{
groupBox1.Enabled = false;
groupBox2.Enabled = false;
listBox1.Enabled = false;
} } }

PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM

  • 1.
    PROGRAMMING USING C# LABMANUAL SARASWATHI RAMALINGAM SRI AKILANDESWARI WOMENS COLLEGE THIRUVALLUVAR UNIVERSITY
  • 2.
    Windows Form Controls(List, Combo, Timer, Group Box, Picture Box) 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 controls {
  • 3.
    public partial classForm1 : Form { private int i; public Form1() { InitializeComponent(); } private void time1() { Timer timer1 = new Timer(); timer1.Interval = 1000; timer1.Enabled = true; timer1.Tick += new EventHandler(timer1_Tick); timer1.Start(); i = 30; } private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  • 4.
    { if (listBox1.SelectedItem =="Computer Quiz") { groupBox2.Enabled = false; } else { groupBox2.Enabled = true; listBox1.Enabled = false; time1(); } if (listBox1.SelectedItem == "Maths Quiz") { groupBox1.Enabled = false; } else { groupBox1.Enabled = true; listBox1.Enabled = false; time1(); } }
  • 5.
    private void button1_Click(objectsender, EventArgs e) { listBox1.Enabled = true; if (groupBox1.Enabled == false || groupBox2.Enabled == false) { MessageBox.Show("Please Select Quiz Mode"); } } private void timer1_Tick(object sender, EventArgs e) { int result = 0; if (comboBox1.SelectedItem == "Undo") { result = result + 5; } if (comboBox2.SelectedItem == "Redo") { result = result + 5; } if (comboBox3.SelectedItem == "Print Preview") { result = result + 5; } if (comboBox4.SelectedItem == "Close a Worksheet") { result = result + 5; } if (comboBox5.SelectedItem == "Insert a Worksheet") { result = result + 5; }
  • 6.
    if (comboBox6.SelectedItem =="62") { result = result + 5; } if (comboBox7.SelectedItem == "11") { result = result + 5; } if (comboBox8.SelectedItem == "25") { result = result + 5; } if (comboBox9.SelectedItem == "108") { result = result + 5; } if (comboBox10.SelectedItem == "1") { result = result + 5; } if (i >= 0) { i = i - 1; textBox1.Text = i + " Seconds"; } if (textBox1.Text == 0 + " Seconds") { MessageBox.Show("Time Out Your score=" + result); this.Close(); } } private void Form1_Load(object sender, EventArgs e) { groupBox1.Enabled = false; groupBox2.Enabled = false; listBox1.Enabled = false; } } }