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

C# Unit4

Windows Forms is a graphical API in .NET Framework used to develop rich client applications. It provides easier interfaces to create desktop applications using controls like labels, textboxes, buttons, etc. A Windows Forms application runs on a desktop computer and allows users to interact with the application through these controls. Common controls include labels to display text, textboxes for input, buttons to trigger actions, and combo boxes, checkboxes, and radio buttons for selection options. Events handle user interactions and actions with the controls.

Uploaded by

giridhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

C# Unit4

Windows Forms is a graphical API in .NET Framework used to develop rich client applications. It provides easier interfaces to create desktop applications using controls like labels, textboxes, buttons, etc. A Windows Forms application runs on a desktop computer and allows users to interact with the application through these controls. Common controls include labels to display text, textboxes for input, buttons to trigger actions, and combo boxes, checkboxes, and radio buttons for selection options. Events handle user interactions and actions with the controls.

Uploaded by

giridhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Module 4:

Graphical User Interface with Windows Forms and


WPF
Windows Forms:
Windows Forms is a set of managed libraries in .NET Framework
designed to develop rich client applications.
It is a graphical API to display data and manage user interactions with
easier deployment and better security in client applications.
 Windows Forms is a Graphical User Interface(GUI) class library
which is bundled in .Net Framework.
 Its main purpose is to provide an easier interface to develop the
applications for desktop, tablet, PCs.
 It is also termed as the WinForms. The applications which are
developed by using Windows Forms or WinForms are known as the
Windows Forms Applications that runs on the desktop computer.
 WinForms can be used only to develop the Windows Forms
Applications not web applications.
 WinForms applications can contain the different type of controls like
labels, list boxes, tooltip etc.
 A windows form application is an application, which is designed to
run on a computer. It will not run on web browser because then it
becomes a web application.
Windows Forms Basics
A Windows forms application is one that runs on the desktop
computer. A Windows forms application will normally have a
collection of controls such as labels, textboxes, list boxes, etc.

Below is an example of a simple Windows form application C#. It


shows a simple Login screen, which is accessible by the user. The user
will enter the required credentials and then will click the Login button
to proceed.

So an example of the controls available in the above application


 This is a collection of label controls which are normally used to
describe adjacent controls. So in our case, we have 2 textboxes, and
the labels are used to tell the user that one textbox is for entering the
user name and the other for the password.
 The 2 textboxes are used to hold the username and password which
will be entered by the user.
 Finally, we have the button control. The button control will normally
have some code attached to perform a certain set of actions. So for
example in the above case, we could have the button perform an
action of validating the user name and password which is entered by
the user.
Control Name Applicable Events Description
Label None It is used to display text on the HTML page.

TextBox TextChanged It is used to create a text input in the form.

Button Click, Command It is used to create a button.

LinkButton Click, Command It is used to create a button that looks similar to the
hyperlink.

ImageButton Click It is used to create an imagesButton. Here, an image


works as a Button.

Hyperlink None It is used to create a hyperlink control that responds to a


click event.

DropDownList SelectedIndexChanged It is used to create a dropdown list control.

ListBox SelectedIndexCnhaged It is used to create a ListBox control like the HTML control.

DataGrid CancelCommand, It used to create a frid that is used to show data. We can
EditCommand, also perform paging, sorting, and formatting very easily
DeleteCommand, with this control.
ItemCommand,
SelectedIndexChanged,
PageIndexChanged,
SortCommand,
UpdateCommand,
ItemCreated,
ItemDataBound

DataList CancelCommand, It is used to create datalist that is non-tabular and used to


EditCommand, show data.
DeleteCommand,
ItemCommand,
SelectedIndexChanged,
UpdateCommand,
ItemCreated,
ItemDataBound

CheckBox CheckChanged It is used to create checkbox.

CheckBoxList SelectedIndexChanged It is used to create a group of check boxes that all work
together.

RadioButton CheckChanged It is used to create radio button.


RadioButtonList SelectedIndexChanged It is used to create a group of radio button controls that
all work together.

Image None It is used to show image within the page.

Panel None It is used to create a panel that works as a container.

PlaceHolder None It is used to set placeholder for the control.

Calendar SelectionChanged, It is used to create a calendar. We can set the default


VisibleMonthChanged, date, move forward and backward etc.
DayRender

AdRotator AdCreated It allows us to specify a list of ads to display. Each time


the user re-displays the page.

Table None It is used to create table.

XML None It is used to display XML documents within the HTML.

Literal None It is like a label in that it displays a literal, but allows us to


create new literals at runtime and place them into this
control.

Label Control
Next comes the Label Control. The label control is used to display a text
or a message to the user on the form. The label control is normally used
along with other controls. Common examples are wherein a label is
added along with the textbox control.
The label indicates to the user on what is expected to fill up in the

textbox.

Button
The Windows Forms Button control allows the user to click it to perform
an action. The Button control· can display both text and images. When
the button is clicked, it looks as if it is being pushed in and released.
Whenever the user clicks a button, the Click event handler is invoked.
You place code in the Click event handler to perform any action you
choose.
The text displayed on the button is contained in the Text property.
List box
A Listbox is used to showcase a list of items on the Windows form. Let’s
see how we can implement this with an example shown below. We will
add a list box to the form to store some city locations.
RadioButton
A Radiobutton is used to showcase a list of items out of which the user
can choose one. Let’s see how we can implement this with an example
shown below. We will add a radio button for a male/female option.
Checkbox
A checkbox is used to provide a list of options in which the user can
choose multiple choices. Let’s see how we can implement this with an
example shown below. We will add 2 checkboxes to our Windows forms.
These checkboxes will provide an option to the user on whether they
want to learn C# or ASP.Net.
Button
A button is used to allow the user to click on a button which would then
start the processing of the form. Let’s see how we can implement this
with an example shown below. We will add a simple button called
‘Submit’ which will be used to submit all the information on the form.
Tool tips:
A tooltip is a small pop-up window that displays some information when
you rollover on a control.

Creating a Tooltip
Tooltip class represents a tooltip control. Once a Tooltip object is
created, we need to call SetToolTip method and pass a control and text.
The following code snippet creates a Tooltip and attaches to a Button
control using SetToolTip method.
 ToolTip toolTip1 = newToolTip();
 toolTip1.ShowAlways = true;
 toolTip1.SetToolTip(button1, "Click me to execute.");
Tooltip Properties
 Active: A tooltip is currently active.
 AutomaticDelay: Automatic delay for the tooltip.
 AutoPopDelay: The period of time the ToolTip remains visible if the
pointer is stationary on a control with specified ToolTip text.
 InitialDelay: Gets or sets the time that passes before the ToolTip
appears.
 IsBaloon: Gets or sets a value indicating whether the ToolTip should
use a balloon window.
 ReshowDelay: Gets or sets the length of time that must transpire
before subsequent ToolTip windows appear as the pointer moves
from one control to another.
 ShowAlways: Displays if tooltip is displayed even if the parent
control is not active.
 ToolTipIcon: Icon of tooltip window.
 ToolTipTitle: Title of tooltip window.
 UseAnimation: Represents whether an animation effect should be
used when displaying the tooltip.
 UseFading: Represents whether a fade effect should be used when
displaying the tooltip.

Mouse Events:
Mouse Events
There are several kinds of mouse events:
Click
This event occurs when the mouse button is released, typically before the
MouseUp event. The handler for this event receives an argument of type
EventArgs. Handle this event when you only need to determine when a
click occurs.

MouseClick
This event occurs when the user clicks the control with the mouse. The
handler for this event receives an argument of type MouseEventArgs.
Handle this event when you need to get information about the mouse
when a click occurs.
DoubleClick
This event occurs when the control is double-clicked. The handler for
this event receives an argument of type EventArgs. Handle this event
when you only need to determine when a double-click occurs.

MouseDoubleClick
This event occurs when the user double-clicks the control with the
mouse. The handler for this event receives an argument of type
MouseEventArgs. Handle this event when you need to get information
about the mouse when a double-click occurs.

MouseDown
This event occurs when the mouse pointer is over the control and the
user presses a mouse button. The handler for this event receives an
argument of type MouseEventArgs.

MouseEnter
This event occurs when the mouse pointer enters the border or client
area of the control, depending on the type of control. The handler for this
event receives an argument of type EventArgs.

MouseHover
This event occurs when the mouse pointer stops and rests over the
control. The handler for this event receives an argument of type
EventArgs.

MouseLeave
This event occurs when the mouse pointer leaves the border or client
area of the control, depending on the type of the control. The handler for
this event receives an argument of type EventArgs.

MouseMove
This event occurs when the mouse pointer moves while it is over a
control. The handler for this event receives an argument of type
MouseEventArgs.

MouseUp
This event occurs when the mouse pointer is over the control and the
user releases a mouse button. The handler for this event receives an
argument of type MouseEventArgs.
MouseWheel
This event occurs when the user rotates the mouse wheel while the
control has focus. The handler for this event receives an argument of
type MouseEventArgs. You can use the Delta property of
MouseEventArgs to determine how far the mouse has scrolled.

Keyboard events
Windows Forms provides two events that occur when a user presses a
keyboard key and one event when a user releases a keyboard key:
The KeyDown event occurs once.
The KeyPress event, which can occur multiple times when a user holds
down the same key.
The KeyUp event occurs once when a user releases a key.
When a user presses a key, Windows Forms determines which event to
raise based on whether the keyboard message specifies a character key or
a physical key. For more information about character and physical keys

Keyboard event Description Results


KeyDown This event is raised when a The handler for KeyDown
user presses a physical key. receives:

A KeyEventArgs parameter,
which provides the KeyCode
property (which specifies a
physical keyboard button).
The Modifiers property (SHIFT,
CTRL, or ALT).
The KeyData property (which
combines the key code and
modifier). The KeyEventArgs
parameter also provides:

You might also like