You are on page 1of 7

Visual programing (CS-692/CS-783)

Mr. Ikram Afzal email: ikram@biit.edu.pk Whatsapp#03345373093


Mr. Umar Farooq email: umar.farooq@biit.edu.pk Whatsapp#03327661819

(Week 7) Lecture # 13:

Objective:

 Date Time Picker


 DateTime class.
 DateTime.Now

Date Time Picker:


The Date Time Picker control allows you to display and collect date and
time with a specified format.

Date time picker

Date time picker

Show Date
Button show Date will show the Selected date of date time picker through message box
Show Time
Show time button will show the time from the date time picker through message box.
Break Apart
Break Apart will break the selected date in Day , Month and year and show the respected text boxes.
Visual programing (CS-692/CS-783)
Mr. Ikram Afzal email: ikram@biit.edu.pk Whatsapp#03345373093
Mr. Umar Farooq email: umar.farooq@biit.edu.pk Whatsapp#03327661819

TxtAddMonths

TxtNewDate

Show New Date


Will add the Months entered in the text box txtAddMonths to the date selected from the date time
picker and show the new date in the text Box txtNewDate.

DateTimePicker2

btnCalculateAge

txtAge

Calculate Age
User will select the date of birth from the dateTimePicker2 and the Calculate
button will calculate the age in the days and show in the text Box txtAge.

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 COMBOBOX
{
public partial class dateTimePickerExample : Form
{
public dateTimePickerExample()
{
InitializeComponent();
}

private void btnDate_Click(object sender, EventArgs e)


{
MessageBox.Show(dateTimePicker1.Value.ToShortDateString());
}
Visual programing (CS-692/CS-783)
Mr. Ikram Afzal email: ikram@biit.edu.pk Whatsapp#03345373093
Mr. Umar Farooq email: umar.farooq@biit.edu.pk Whatsapp#03327661819

private void btnTime_Click(object sender, EventArgs e)


{
MessageBox.Show(dateTimePicker1.Value.ToShortTimeString());
}

private void btnBreak_Click(object sender, EventArgs e)


{
txtDay.Text = dateTimePicker1.Value.DayOfWeek.ToString();
txtYear.Text = dateTimePicker1.Value.Year.ToString();
txtMonth.Text = dateTimePicker1.Value.Month.ToString();
}

private void btnCalculateAge_Click(object sender, EventArgs e)


{

txtAge.Text=dateTimePicker1.Value.Subtract(dateTimePicker2.Value).TotalDays.T
oString();
}

private void btnShowNew_Click(object sender, EventArgs e)


{
txtAge.Text =
dateTimePicker1.Value.AddMonths(int.Parse(txtAddMonths.Text)).ToShortDateStri
ng();
}
}
}
Visual programing (CS-692/CS-783)
Mr. Ikram Afzal email: ikram@biit.edu.pk Whatsapp#03345373093
Mr. Umar Farooq email: umar.farooq@biit.edu.pk Whatsapp#03327661819

(Week 7) Lecture # 14:

Objective:

 List Box Example

List Box:

listBox

lstbxSubject
lstbxSelected
Visual programing (CS-692/CS-783)
Mr. Ikram Afzal email: ikram@biit.edu.pk Whatsapp#03345373093
Mr. Umar Farooq email: umar.farooq@biit.edu.pk Whatsapp#03327661819

To ADD the items in the list Box click this button


and select the edit items

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 COMBOBOX
{
public partial class listViewExample : Form
{
public listViewExample()
Visual programing (CS-692/CS-783)
Mr. Ikram Afzal email: ikram@biit.edu.pk Whatsapp#03345373093
Mr. Umar Farooq email: umar.farooq@biit.edu.pk Whatsapp#03327661819

{
InitializeComponent();
}

private void btnSelect_Click(object sender, EventArgs e)


{
int index = lstbxSubjects.SelectedIndex;
if (index == -1)
{

}
else
{
string item = lstbxSubjects.SelectedItem.ToString();
lstbxSubjects.Items.RemoveAt(index);
lstbxSelected.Items.Add(item);
}
}

private void btnSelectAll_Click(object sender, EventArgs e)


{
foreach (string item in lstbxSubjects.Items)
{
lstbxSelected.Items.Add(item);

}
lstbxSubjects.Items.Clear();

private void btnUSel_Click(object sender, EventArgs e)


{
int index = lstbxSelected.SelectedIndex;
if (index != -1)
{
string item = lstbxSelected.SelectedItem.ToString();
lstbxSelected.Items.RemoveAt(index);
lstbxSubjects.Items.Add(item);
}
}

private void btnUSelAll_Click(object sender, EventArgs e)


{
foreach (string item in lstbxSelected.Items)
{
lstbxSubjects.Items.Add(item);

}
lstbxSelected.Items.Clear();
}

}
}
Visual programing (CS-692/CS-783)
Mr. Ikram Afzal email: ikram@biit.edu.pk Whatsapp#03345373093
Mr. Umar Farooq email: umar.farooq@biit.edu.pk Whatsapp#03327661819

You might also like