GUI Session03

Download as pps, pdf, or txt
Download as pps, pdf, or txt
You are on page 1of 29

GUI Applications

Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Objectives

In this session, you will learn to:


Compare CUI and GUI
Use dialog boxes
Use Event-driven programming
Use Windows Forms controls

Ver. 1.0 Slide 1 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Knowledge Byte

Comparing CUI and GUI


An application can be developed by using any of the following
interface:
Character User Interface (CUI)
Graphical User Interface (GUI)
Depending upon user preferences, any of the two interfaces
can be used.

Ver. 1.0 Slide 2 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Knowledge Byte (Contd.)

Character User Interface (CUI):


CUI uses a command line interpreter to interact with an operating
system or an application.
A simple CUI:
1. Displays a prompt.
2. Accept a command.
3. Execute the command.
4. Displays the result, or error message.
Drawbacks of CUI are:
Various text commands may confuse a user.
CUI usage is error prone.
CUI usage requires the user to remember a large number of
commands.

Ver. 1.0 Slide 3 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Knowledge Byte (Contd.)

Graphical User Interface (GUI):


GUI is easier to learn and use.
It consists of various elements such as windows, icons, and
menus.
In GUI, the display is divided into a bordered area known as a
window.

Ver. 1.0 Slide 4 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Knowledge Byte (Contd.)

Advantages of GUI:
GUI enables a user to run an application by using easy to
remember and convenient to use options, such as menus, icons,
and toolbars.
GUI eliminates the need to remember text commands to perform
complicated operations.
GUI provides visual feedback for the user.

Ver. 1.0 Slide 5 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Knowledge Byte (Contd.)

Using Dialog Boxes


Dialog boxes are used by an application to interact with the
user.
Dialog boxes are used to collect information from the user.
There are various types of dialog boxes out of which modal
and modeless dialog boxes are frequently used in application.

Ver. 1.0 Slide 6 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Knowledge Byte (Contd.)

Modal Dialog Box:


Forces a user to make a decision.
Can be used to issue an alert message that has to be acted upon
before the user can perform any other operation.
Modeless Dialog Box:
Displays information or options to a user without interrupting the
user.
Allows a user to work in the window while the modeless dialog
box is displayed on the screen.

Ver. 1.0 Slide 7 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Knowledge Byte (Contd.)

Using Event-Driven Programming


Event-driven programming does not follow any linear
sequence for the execution of code.
Logical sections of the code are placed inside events.
Events can be executed in any sequence depending upon the
user’s actions.

Ver. 1.0 Slide 8 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Knowledge Byte (Contd.)

Sequence of Events in Windows Forms is displayed in the


following figure.
Load

Activated

Shown

Deactivated

Form Closing Activated

Form Closed

Deactivated

Ver. 1.0 Slide 9 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Knowledge Byte (Contd.)

Using Windows Forms Controls


A large number of controls are provided by Microsoft Visual
Studio 2005 to create effective and user-friendly GUI
applications.
Some of these controls are:
Panel
TabControl
MonthCalendar

Ver. 1.0 Slide 10 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Knowledge Byte (Contd.)

Panel Control:
Is similar to a container control.
Acts as a parent control.
Is used to define a common behavior for all child controls.
TabControl Control:
Acts as a container for logical groups of different sets of controls.
Allows users to see one logical group of controls at any point of
time.
Allows users to switch from one logical group of controls to
another by selecting the appropriate tab.

Ver. 1.0 Slide 11 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Knowledge Byte (Contd.)

MonthCalendar Control:
Is used to select and view information pertaining to the date.
Can be used to display the date on the basis of the regional
settings available within the control panel.

Ver. 1.0 Slide 12 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Knowledge Byte (Contd.)

Loading Controls at Run Time:


Controls are added to the Windows form at design time.
In some situations, the type of controls to be added cannot be
determined during design time.
Such situations can be handled by:
Placing all the required controls on the feedback form at the design
time with their Visible property set to FALSE. During run time, the
Visible property of the required controls can be set to TRUE
depending upon the user’s input.
Loading the required controls dynamically during runtime on the basis
of the user’s input.

Ver. 1.0 Slide 13 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Knowledge Byte (Contd.)

The advantages of loading controls at the run time are:


A customized view of the Windows form can be provided to the
user.
A lot of system resources can be saved during execution of the
application.

Ver. 1.0 Slide 14 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Best Practices

Whenever a new application is developed:


All the methods defined inside the project should be declared
with the private access modifier.
Whenever a private method is required in a derived class for
overriding, replace it by the protected modifier.
Whenever a private method is required to be called by an
object of another class, replace the private modifier by
public.
If you want to use the functionality of existing forms or
controls with some changes, you should try to create new
forms and controls by inheriting the existing forms and
controls.
You should minimize code in functions and procedures. This
leads to clear and logical program architecture and greater
code reusability.

Ver. 1.0 Slide 15 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Tips and Tricks

Use the auto-hide feature to hide a window that is not in


use. You can enable the auto-hide feature by performing the
following steps:
1. Right-click the title bar of the window.
2. Select the Auto Hide option from the pop-up menu.

Ver. 1.0 Slide 16 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Tips and Tricks (Contd.)

You can incrementally search any text in the source code by


performing the following steps:
1. Click the region in the source code window after which the text
needs to be searched.
2. Press Ctrl+I.
3. Type the text you want to search. As you type the text, that
text gets highlighted in source code window.
4. Press the F3 button to search the next occurrence of the same
text.

Ver. 1.0 Slide 17 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Tips and Tricks (Contd.)

You can use the following shortcut keys to open various


types of windows:
Press the F4 key to open the Properties window.
Press Ctrl+ Alt+ L to open the Solution Explorer window.
Press Ctrl+ Alt+ O to open the Output window.
You can use the following shortcut keys to format the code
in the source-code window:
Select the code and press Ctrl+U to convert the selected code
to lower case.
Select the code and press Ctrl+Shift+U to convert the
selected code to upper case.
Select the code and press Ctrl+K+C to comment the selected
code.
Select the code and press Ctrl+K+U to uncomment the
selected code.

Ver. 1.0 Slide 18 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

FAQs

What are the different types of projects that can be


developed using Microsoft Visual Studio 2005?
By using Microsoft Visual Studio 2005, you can create:
Console applications
Windows Applications
Web applications
Web services
Class library
Windows Control Library
Web Control Library

How many projects can a solution have?


A solution can contain any number of projects. There is no limit
to it.

Ver. 1.0 Slide 19 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

FAQs (Contd.)

What do you mean by debugging an application?


Debugging is the process of discovering and removing bugs
from code.

What is a debugger?
A debugger refers to software that helps in identifying and
removing bugs from the program. When you execute your
application, the debugger attaches itself to the program and
provides you with various types of information such as the run
time state of the program and values of the variables. You can
also specify the point in your code where you want to see
values of different variables during run time. These points are
known as break points.

Ver. 1.0 Slide 20 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

FAQs (Contd.)

How can you execute your application with and without


attaching a debugger?
To execute the application by attaching a debugger, select
DebugStart Debugging. To execute an application without
attaching a debugger, select DebugStart Without
Debugging.

Ver. 1.0 Slide 21 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Challenge

Identify the correct steps in the process of compilation of the


source code within the .NET Framework.
a. 1. The compiler translates the code into Intermediate
Language (IL).
2. The JIT compiler converts the IL into machine language during
runtime.
b. 1. The compiler translates the code into machine language.
2. The JIT compiler converts the machine language.
c. 1. The JIT compiler translates the code into Intermediate Language
(IL).
2. The IL code is converted into the machine language during
runtime.
d. 1. The JIT compiler translates the code into Intermediate Language
(IL).
2. The JIT compiler then converts the IL into the machine language
during runtime.

Ver. 1.0 Slide 22 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Challenge (Contd.)

Answer:
a 1. The compiler translates the code into Intermediate
Language (IL).
2. The JIT compiler converts the IL into machine language during
runtime.

Ver. 1.0 Slide 23 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Challenge (Contd.)

John has been assigned a task of developing a student


registration system in the .NET Framework. To accomplish
this task, he has developed various forms for different
purposes. In addition, he has added different classes and
images in his project. Which of the following windows would
enable John to view the list of the items he has added in his
project?
a. Properties window
b. Solution Explorer window
c. Dynamic Help window
d. Output window

Answer:
b. Solution Explorer window

Ver. 1.0 Slide 24 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Challenge (Contd.)

Henry is developing a Windows-based application for a


library system in .NET. While developing the application, he
constantly needs to refer to the Solution Explorer window to
add or remove items from the project. Therefore, he wants
to place the Solution Explorer window fixed along the edge
of the parent window. Which navigation feature should John
use?
a. Floating
b. Hide
c. Dockable
d. Auto hide

Answer:
c. Dockable

Ver. 1.0 Slide 25 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Challenge (Contd.)

Sam is developing a Windows-based application in C#.


Currently, there are two forms in his application, Form1 and
Form2. Form1 is set as the startup form. He needs Form2 to
be displayed when he clicks the button, named Show, on
Form1. What code should Sam write on the click event of
the button control to accomplish his task?
a. Form1 obj = new Form1();
obj.Close();
b. Form1 obj = new Form1();
obj.Hide();
c. Form2 obj = new Form2();
obj.Activate();
d. Form2 obj = new Form2();
obj.Show();

Ver. 1.0 Slide 26 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Challenge (Contd.)

Answer:
d. Form2 obj = new Form2();
obj.Show();

Ver. 1.0 Slide 27 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Challenge (Contd.)

John is developing a Windows-based application for library


management system in .NET. He has added a new form,
Form1, to the project. This form contains a listbox called
listBooks, which would display a list of all the books in the
library. However, he does not want the listbox to be displayed
initially when the form loads. Which of the following code
snippet would enable John to accomplish this task?
a. private void Form1_Load(EventArgs e, object sender)
{ listBooks.Hide(); }
b. private void Form1_Load(object sender, EventArgs e)
{ listBooks.Hide(); }
c. private void Form1_Load(object sender)
{ listBooks.Hide(); }
d. private void Form1_Load(EventArgs e)
{ listBooks.Hide(); }

Ver. 1.0 Slide 28 of 29


GUI Applications
Installing Development
Windows XP Professional Using Using .NET
Attended Framework
Installation

Challenge (Contd.)

Answer:
b. private void Form1_Load(object sender, EventArgs e)
{ listBooks.Hide(); }

Ver. 1.0 Slide 29 of 29

You might also like