web view06.05.2016 · mit 31043, lab exercise: exam organizer. design a form as shown...

5
MIT 31043, Lab Exercise: Exam Organizer 1. Design a form as shown below MIT 31043, S. Sabraz Nawaz, Exam Schedule Program: Sample Code Page 1

Upload: letuyen

Post on 05-Feb-2018

214 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Web view06.05.2016 · MIT 31043, Lab Exercise: Exam Organizer. Design a form as shown below

MIT 31043, Lab Exercise: Exam Organizer1. Design a form as shown below

MIT 31043, S. Sabraz Nawaz, Exam Schedule Program: Sample Code Page 1

Page 2: Web view06.05.2016 · MIT 31043, Lab Exercise: Exam Organizer. Design a form as shown below

2. Add ColorDialog, SaveFileDialog, OpenFileDialog, PrintDialog and PrintDocument dialogs

3. Add the following coding

private void scheduleExamButton_Click(object sender, EventArgs e) { scheduleListbox.Items.Clear(); scheduleListbox.Items.Add("Exam Date and Time is: " + examDateTimePicker.Value); scheduleListbox.Items.Add("--------------------------------------------------------------------------"); scheduleListbox.Items.Add(""); scheduleListbox.Items.Add("Exam Candidates:");

foreach (object student in studentsCheckedListbox.CheckedItems ) { scheduleListbox.Items.Add("\t" + student.ToString()); }

scheduleListbox.Items.Add(""); if (MCQRadioButton.Checked) { scheduleListbox.Items.Add("Exam Type: MCQ"); } else if (practicalRadioButton.Checked) { scheduleListbox.Items.Add("Exam Type: Practical");} else if (structureRadioButton.Checked) {scheduleListbox.Items.Add("Exam Type: Structure Type");} else if (essayRadioButton.Checked) {scheduleListbox.Items.Add("Exam Type: Essay Type");}

scheduleListbox.Items.Add(""); scheduleListbox.Items.Add("Exam Location: " + locationsCombobox.Text); }

MIT 31043, S. Sabraz Nawaz, Exam Schedule Program: Sample Code Page 2

Page 3: Web view06.05.2016 · MIT 31043, Lab Exercise: Exam Organizer. Design a form as shown below

private void clearScheduleButton_Click(object sender, EventArgs e) { foreach (int item in studentsCheckedListbox.CheckedIndices) { studentsCheckedListbox.SetItemCheckState(item, CheckState.Unchecked); }

scheduleListbox.Items.Clear();

locationsCombobox.Text = ""; } private void saveScheduleButton_Click(object sender, EventArgs e) { string fileName; examScheduleSaveDialog.Title = "Save Exam Schedule"; examScheduleSaveDialog.DefaultExt = "txt"; examScheduleSaveDialog.AddExtension = true; examScheduleSaveDialog.Filter = "Text File(*.txt)|*.txt"; examScheduleSaveDialog.ShowDialog(); fileName = examScheduleSaveDialog.FileName; StreamWriter scheduleOutput = new StreamWriter(fileName); foreach (string lineItem in scheduleListbox.Items) { scheduleOutput.WriteLine(lineItem); } scheduleOutput.Close(); }

private void openScheduleButton_Click(object sender, EventArgs e) { string fileName; examScheduleOpenDialog.Filter = "Text Files (*.txt)|*.txt"; examScheduleOpenDialog.Title = "Open Exam Schedule"; examScheduleOpenDialog.ShowDialog(); fileName = examScheduleOpenDialog.FileName;

MIT 31043, S. Sabraz Nawaz, Exam Schedule Program: Sample Code Page 3

Page 4: Web view06.05.2016 · MIT 31043, Lab Exercise: Exam Organizer. Design a form as shown below

scheduleListbox.Items.Clear(); //Clears the existing contents.

StreamReader scheducleInput = new StreamReader(fileName);

while (scheducleInput.Peek() != -1) { scheduleListbox.Items.Add(scheducleInput.ReadLine()); } scheducleInput.Close(); }

private void changeColorButton_Click(object sender, EventArgs e) { if (scheduleColorDialog.ShowDialog() == DialogResult.OK) { scheduleListbox.ForeColor= scheduleColorDialog.Color; } }

private void examPrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { //Assign String value to the printContent variable which has been declared at class level foreach (string lineItem in scheduleListbox.Items) { printContent = printContent + "\n" + lineItem; } e.Graphics.DrawString(printContent, new Font("Times New Roman", 12), Brushes.Black, 80, 80); }

private void printScheduleButton_Click(object sender, EventArgs e) { //calling the Print() method of the printDocument component.

examPrintDialog.Document = examPrintDocument; if (examPrintDialog.ShowDialog() == DialogResult.OK) { examPrintDocument.Print(); } }

MIT 31043, S. Sabraz Nawaz, Exam Schedule Program: Sample Code Page 4