EDP Part 2

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 22

Event-driven programming using C#

Kitaw A.
Controls: MaskedTextBox
A MaskedTextBox control provides a validation mechanism for user input
on a TextBox
For example, if you want a TextBox to accept a phone number in
+2519******** format, you can set masking in the MaskedTextBox
Properties
Mask: masks the default text property
The mask can be set using Input Mask dialog where we can select a predefined mask
Controls: MaskedTextBox
Controls: MaskedTextBox
Here is a list and description of masking characters.
0 – Digit, required. Value between 0 and 9.
9 – Digit or space, optional.
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.
A - Alphanumeric, required.
a - Alphanumeric, optional.
\ - Escape. Escapes a mask character, turning it into a literal. "\\" is the escape sequence
for a backslash.
All non-mask elements will appear as themselves within MaskedTextBox and cannot be
moved or deleted by the user.
Controls: MaskedTextBox
For example, if you want a TextBox to accept a phonenumber in
+2519******** format, you can set masking in the MaskedTextBox named
mTextPhone as
mTextPhone.Mask=“+251\\900000000”;
Controls: GroupBoxes and Panels
GroupBoxes and Panels are typically used to group several controls of
similar functionality or several controls that are related in a GUI
All of the controls in a GroupBox or Panel move together when the
GroupBox or Panel is moved
Furthermore, GroupBoxes and Panels can also be used to show or hide a set
of controls at once
When you modify a container’s Visible property, it toggles the visibility of
all the controls within it
The primary difference between these two controls is that GroupBoxes can
display a caption (i.e., text) and do not include scrollbars, whereas Panels
can include scrollbars and do not include a caption.
Controls: GroupBoxes and Panels
GroupBox properties
Text: Specifies the caption text displayed at the top of the GroupBox.
Panel properties
AutoScroll: Indicates whether scrollbars appear when the Panel is too small
to display all of its controls
The default value is false.
Controls: ToolTips
Tool Tip:
The helpful text that appears when the mouse hovers over an item in a GUI
Common Properties
AutoPopDelay: The amount of time (in milliseconds) that the tool tip appears while
the mouse is over a control.
IsBalloon: A Boolean property, determines whether the tool tip will take on a balloon
form
Its default value is false

ToolTipTitle: Determines title of the tool tip


Controls: ToolTips
Once a ToolTip is added to a Form, a new property appears in the Properties
window for the Form’s other controls
This property appears in the Properties window as ToolTip on, followed by
the name of the ToolTip component
This property is used to set the tool tip text for any control on the form
Controls: PictureBoxes
A PictureBox displays an image
The image can be one of several formats, such as bitmap, PNG (Portable
Network Graphics), GIF (Graphics Interchange Format) and JPEG
Common Properties
Image: Sets the image to display in the PictureBox
Size Mode: Enumeration that controls image sizing and positioning
Values are Normal (default), StretchImage, AutoSize, CenterImage, and Zoom.
Controls: PictureBoxes
Normal: places the image in the PictureBox’s top-left corner, and
CenterImage: puts the image in the middle
StretchImage: resizes the image to fit in the PictureBox
AutoSize: resizes the PictureBox to hold the image
Zoom: resizes the image to fit the PictureBox but maintains the original
aspect ratio
Controls: 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
Properties:
Minimum: Gets or sets the minimum value of the range of the control
Maximum: Gets or sets the maximum value of the range of the control.
Step: Gets or sets the amount by which a call to the PerformStep() method
increases the current position of the progress bar.
Value: Gets or sets the current position of the progress bar.
Method:
PerformStep: Advances the current position of the progress bar by the
amount of the Step property
Controls: Menu
Menus provide groups of related commands for Windows Forms apps
Although these commands depend on the program, some—such as Open
and Save—are common to many apps
Menus are an integral part of GUIs, because they organize commands
without “cluttering” the GUI
Controls: Menu
To create a menu, open the Toolbox and drag a MenuStrip control onto the
Form
This creates a menu bar across the top of the Form (below the title bar)
You can now use design mode to create and edit menus for your app
Menus, like other controls, have properties and events, which can be
accessed through the Properties window
To add menu items to the menu, click the Type Here TextBox and type the
menu item’s name
This action adds an entry to the menu of type ToolStripMenuItem
After you press the Enter key, the menu item name is added to the menu
Then more Type Here TextBoxes appear, allowing you to add items
underneath or to the side of the original menu item
Controls: Menu
To add other shortcut keys (e.g., Ctrl + F9) for menu items, set the ShortcutKeys
property of the appropriate ToolStripMenuItems
Controls: ContextMenu
Represents a shortcut menu
C# context menus are the menus that pop up
when the user clicks with the right-hand mouse
button over a control or area in a Windows form
• They are called context menus because the menu
is usually specific to the object over which the mouse
was clicked
Controls: ContextMenu
Context menus are also sometimes referred to as Popup menus or Shortcut
menus
Context menu is designed just like a Menu strip is designed
After a context menu is designed it has to be assigned to a from or any other
control using the ContextMenuStrip property
Controls: NotifyIcon
NotifyIcon is a component in Windows Forms that is used to notify users by
displaying an icon and an optional popup Balloon tooltip in the notification
area of the system taskbar
A context menu can also be added to the NotifyIcon that can be accessed by
clicking the right mouse button on the icon
Properties:
Icon: Gets or sets the current icon
BalloonTipTitle: Gets or sets the title of the balloon tip displayed on the
NotifyIcon.
BalloonTipText: Gets or sets the text to display on the balloon tip
associated with the NotifyIcon.
Controls: NotifyIcon
Properties:
Visible: Gets or sets a value indicating whether the icon is visible in the
notification area of the taskbar
ContextMenu: Gets or sets the shortcut menu for the icon.
Method:
ShowBalloonTip(Int32): Displays the balloon tip in the taskbar.
Dates and Times in C#
Three immutable structs in the System namespace do the job of
representing dates and times: DateTime, DateTimeOffset, and TimeSpan
DateTime:
defines constructors that accept integers for the year, month, and day and optionally,
the hour, minute, second, and millisecond
DateTime have static properties:
Now: returns the current date and time
Today: returns the current date
Dates and Times in C#
TimeSpan
A TimeSpan represents an interval of time
TimeSpan can be constructed by subtracting one DateTime from another
TimeSpan span=DateTime.Now.AddYears(3)-DateTime.Now;
MessageBox.Show(span.Days.ToString());
Controls: DateTimePicker
The DateTimePicker can be used to retrieve date and time information from
the user
A DateTimePicker’s Value property stores a DateTime object, which always
contains both date and time information.
You can retrieve the date information from the DateTime object by using
property Date
Properties
Format: Sets the format of the date and/or time used for the date and/or time displayed
in the control
CustomFormat: Sets the custom format string for the date and/or time displayed in the
control
MaxDate: The maximum date and time that can be selected
MinDate: The minimum date and time that can be selected

You might also like