0% found this document useful (0 votes)
3 views

Lecture 2 2nd Course C#

The document outlines a lecture on advanced C# programming, focusing on various controls such as Text Password, DateTimePicker, Menu Control, Timer, and Progress Bar. It provides code examples for implementing these controls in Windows-based applications. Additionally, it explains the functionality and usage of each control in the context of user interface development.

Uploaded by

yousif
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lecture 2 2nd Course C#

The document outlines a lecture on advanced C# programming, focusing on various controls such as Text Password, DateTimePicker, Menu Control, Timer, and Progress Bar. It provides code examples for implementing these controls in Windows-based applications. Additionally, it explains the functionality and usage of each control in the context of user interface development.

Uploaded by

yousif
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

‫س‬ ‫ح‬‫ل‬‫ا‬ ‫ل‬ ‫ع‬ ‫س‬‫ق‬ ‫م‬ ‫ل‬ ‫مع‬‫كل عل الح س تكن ل جي ال‬

‫ م وم ا وب‬/ ‫ية وم ا وب و و و ا و اب‬


3ed Class – 2nd Course

Subject: Programming Language II (Advance C#)

Lecturer: Dr. Yousif A. Hamad


Lecture No 2
C# Objects (controls)
1. Text Password showing
2. Date Time Picker
3. Menu Control
4. Timer & Progress Bar

Text Password showing


Example 1: Write a C# code to hide the password in the textbox using
checkbox button
private void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
textBox2.UseSystemPasswordChar = false;
else
textBox2.UseSystemPasswordChar = true;

}
Date Time Picker
The DateTimePicker control allows you to display and collect date and time
from the user with a specified format.

Example 2: Write a Windows based application to design the following:


// label4.Text = dateTimePicker1.Value.ToString();
// label4.Text = dateTimePicker1.Value.ToShortDateString();
// label5.Text = dateTimePicker1.Value.ToShortTimeString();
label5.Text = dateTimePicker1.Value.Date.Year.ToString();

Menu Control
A Menu on a Windows Form is created with a MainMenu object, which is a
collection of MenuItem objects. MainMenu is the container for the Menu
structure of the form and menus are made of MenuItem objects that represent
individual parts of a menu. You can add menus to Windows Forms at design
time by adding the MainMenu component and then appending menu items to
it using the Menu Designer. After drag the Menustrip on your form you can
directly create the menu items by type a value into the "Type Here" box on the
menubar part of your form. From the following picture you can understand how
to create each menu items on main menu Object.
Timer & Progress Bar
Progress Bar is a control that an application can use to indicate the progress of
a lengthy operation such as calculating a complex result, downloading a large
file from the Web etc. ProgressBar controls are used whenever an operation
takes more than a short period of time. The Maximum and Minimum properties
define the range of values to represent the progress of a task.
The Timer Control plays an important role in the development of programs both
Client side and Server side development as well as in Windows Services. With
the Timer Control we can raise events at a specific interval of time without the
interaction of another thread.
Example 3: Write a Windows based application to design the form below:
private void timer1_Tick(object sender, EventArgs e)
{
progressBar1.Value = progressBar1.Value + 10;
label1.Text = "%"+ progressBar1.Value.ToString();
if(progressBar1 .Value ==100)
{
Application.Exit();
}}

Example 4: Write a Windows based application to design the form below:


private void Button1_Click(object sender, EventArgs e)
{
timer1.Start();
}
private void Timer1_Tick(object sender, EventArgs e)
{
progressBar1.Increment(5);
label1.Text = progressBar1.Value.ToString()+" % process";
if (progressBar1.Value == 150)
{
DepInfo dep = new DepInfo();
dep.Show();
this.Hide();
timer1.Stop();
dep.button1.Text = "My test program";
// dep.button1.Enabled = false;
dep.button1.Visible = false;
}}
Example 5: Write a Windows based application to design the following forms:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int o=0, m=0, s = 0;
private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
}
private void button3_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
o = 0; s = 0; m= 0;
label1.Text = o.ToString() + ":" + m.ToString() + ":" +
s.ToString();
}
private void button4_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
textBox1.Text = label1.Text;
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
label1 .Text =o.ToString() + ":" + m.ToString() + ":" + s.ToString();
if(s==60)
{
m++;
s = 0;
if(m==60)
{
o++;
m = 0;
if(o==24)
{
o = 0;
}}}
s++;
}}}

You might also like