Professional Documents
Culture Documents
Presentation
Names Registration Numbers
M Faraz Saleem FA16-BCS-111
Ehtasam Tariq FA16-BCS-009
Ali Raza FA16-BCS-003
M Imran FA16-BCS-071
Hassan Raza FA16-BCS-051
ProgressBar in C# windows forms
What is ProgressBar
• A ProgressBar control is used to represent the progress of a lengthy
operation that takes time where a user must wait for the operation to
be finished.
• A 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.
Creating ProgressBar
• Design-time: To create a ProgressBar
control at design-time, you simply drag a
ProgressBar control from the Toolbox
and drop onto a Form in Visual Studio.
After you the drag and drop, a
ProgressBar is created on the Form; for
example the ProgressBar1 is added to
the form and looks as in Figure 1.
Setting ProgressBar Properties
• After you place a ProgressBar
control on a Form, the next step is
to set the properties.
• The easiest way to set the
properties is from the Properties
Window. You can open the
Properties window by pressing F4
or right-clicking on a control and
selecting the "Properties" menu
item. The Properties window looks
as in Figure.
Setting ProgressBar Property
• Name: The Name property represents a unique name of a
ProgressBar control. It is used to access the control in the code. The
following code snippet sets and gets the name and text of a
ProgressBar control.
• C# Code:
PBar.Name = "ProgresBar1";
Positioning a ProgressBar
12
• Star the visual studio
• This program just displays such window:
Label
Control
PictureBox
Button Control
Control
• Click Ok
14
• Right-click anywhere on the Form to display the Form’s properties
in the Properties window.
• Click in the textbox to the right of the Text property box and type
“A Simple Program” (Fig. 2)
Name and type of control
Enabled sizing
handles
Label control
in the Toolbox
20
• Set the AutoSize property to False
• If the AutoSize property is set to True, it automatically
resizes the Label to fit its text
• We will change it, and we don’t want automatic resizing
AutoSize
property
Ellipsis button
Current font
Font sample
24
Add picture in project by right clicking on project from solution
1.Click add
2.Then click Existing Items..
And move to the directory and select pic and hit the ok button
Added Picture
Using Visual Programming to
Create a Simple Program that Displays Text and an
Image
• Click the PictureBox to display its properties in the
Properties window
• The Image property displays a preview of the image, if one
exists.
26
Using Visual Programming to Create … (Cont.)
• Select File >> Save All to save the entire solution
27
Using Visual Programming to Create … (Cont.)
• Select Debug >> Start Debugging to compile and
execute the program (Fig. 17).
Close box
Form
Running program
• A MaskedTextBox control provides a validation mechanism for user input on a Form. For example, if you want
a TextBox to accept a date in mm/dd/yyyy format, you can set masking in the MaskedTextBox.
In this article, I will discuss how to create a MaskedTextBox control in Windows Forms at design-time as well
as run-time. After that, I will continue discussing various properties and methods available for the
MaskedTextBox control.
Creating a MaskedTextBox
We can create a MaskedTextBox control using a Forms designer at design-time or using the MaskedTextBox
class in code at run-time (also known as dynamically).
To create a MaskedTextBox control at design-time, you simply drag and drop a MaskedTextBox control from
Toolbox to a Form in Visual Studio. After you drag and drop a MaskedTextBox on a Form, the MaskedTextBox
looks like Figure 1. Once a MaskedTextBox is on the Form, you can move it around and resize it using mouse
and set its properties and events.
• Creating a MaskedTextBox control at run-time is merely a work of creating
an instance of MaskedTextBox class, setting its properties and adding
MaskedTextBox class to the Form controls.
After you place a MaskedTextBox control on a Form, the next step is to set properties.
The easiest way to set properties is from the Properties Window. You can open Properties window by pressing F4 or
right click on a control and select Properties menu item. The Properties window looks like Figure 2.
• Location, Height, Width, and Size
The Location property takes a Point that specifies the starting position of the MaskedTextBox on a Form. The Size property specifies the size of
the control. We can also use Width and Height property instead of Size property. The following code snippet sets Location, Width, and Height
properties of a MaskedTextBox control.
• dynamicMaskedTextBox.Location = newPoint(20, 150);
• dynamicMaskedTextBox.Height = 40;
• dynamicMaskedTextBox.Width = 300;
• Background, Foreground, BorderStyle
BackColor and ForeColor properties are used to set background and foreground color of a MaskedTextBox respectively. If you click on these
properties in Properties window, the Color Dialog pops up.
Alternatively, you can set background and foreground colors at run-time. The following code snippet sets BackColor and ForeColor properties.
• dynamicMaskedTextBox.BackColor = Color.Red;
• dynamicMaskedTextBox.ForeColor = Color.Blue;
• You can also set borders style of a MaskedTextBox by using the BorderStyle property. The BorderStyle property is represented by a BorderStyle
enumeration that has three values – FixedSingle, Fixed3D, and None. The default value of border style is Fixed3D. The following code snippet
sets the border style of a MaskedTextBox to FixedSingle.
• dynamicMaskedTextBox.BorderStyle = BorderStyle.FixedSingle;
• Name
Name property represents a unique name of a MaskedTextBox control. It is used to access the control in the code.
The following code snippet sets and gets the name and text of a MaskedTextBox control.
• dynamicMaskedTextBox.Name = "DynamicMaskedTextBox";
• string name = dynamicMaskedTextBox.Name;
• Text, TextAlign, and TextLength
Text property of a MaskedTextBox represents the current text of a MaskedTextBox control. The TextAlign property
represents text alignment that can be Left, Center, or Right. The TextLength property returns the length of a
MaskedTextBox contents.
The following code snippet sets the Text and TextAlign properties and gets the size of a MaskedTextBox control.
• dynamicMaskedTextBox.Text = "I am Dynamic MaskedTextBox";
• dynamicMaskedTextBox.TextAlign = HorizontalAlignment.Center;
• int size = dynamicMaskedTextBox.TextLength;
• Font
Font property represents the font of text of a MaskedTextBox control. If you click on the Font property in Properties window, you will see Font
name, size and other font options. The following code snippet sets Font property at run-time.
Maximum Length
You can restrict the number of characters in a MaskedTextBox control by setting MaxLength property. The following code snippet sets the
maximum length of a MaskedTextBox to 50 characters.
• dynamicMaskedTextBox.ReadOnly = true;
• dynamicMaskedTextBox.MaxLength = 50;
• Masking Related Properties
Mask
Masks the default property and represents the format of the input can be accepted by a control. We can set Mask property by clicking on the
control and click on the little handler and select Set Mask link as you can see in Figure 3.
• The following code snippet sets the Mask property at run-time.
• dynamicMaskedTextBox.Mask = "00/00/0000";
• Here is a list and description of masking characters.
• 0 – Digit, required. Value between 0 and 9.
• 9 – Digit or space, optional.
• # - Digit or space, optional. If this position is blank in the mask, it will be
rendered as a space in the Text property.
• L - Letter, required. Restricts input to the ASCII letters a-z and A-Z.
• ? - Letter, optional. Restricts input to the ASCII letters a-z and A-Z.
• & - Character, required.
• C - Character, optional. Any non-control character.
• A - Alphanumeric, required.
• a - Alphanumeric, optional.
• . - Decimal placeholder.
• , - Thousands placeholder.
• : - Time separator.
• / - Date separator.
• $ - Currency symbol.
• < - Shift down. Converts all characters that follow to lowercase.
• > - Shift up. Converts all characters that follow to uppercase.
• | - Disable a previous shift up or shift down.
• \ - Escape. Escapes a mask character, turning it into a literal. "\\" is the escape sequence for a backslash.