Documente Academic
Documente Profesional
Documente Cultură
(GUI) Programming
Introduction
• A graphical user interface (GUI) allows a user to
interact visually with a program.
• GUIs are built from GUI controls (which are
sometimes called components or widgets—short for
window gadgets).
• GUI controls are objects that can display information
on the screen or enable users to interact with an app
via the mouse, keyboard or some other form of input
(such as voice commands).
Windows Form
• Windows Forms is one library
that can be used to create
GUIs.
• A Form is a graphical element
that appears on your
computer’s desktop; it can be
a dialog, a window or an MDI
window (multiple document
interface window)
• Windows Form can be
viewed in the left side
picture.
Controls
• A control consist components which
is used to design the interface of
Apps.
• The real strength of using C# for
Windows applications lies in the
number of controls that you can add
to your applications.
• The System.Windows.Forms
namespace includes many classes
that you can add to your form
representing controls with names
such as Button, Label, TextBox,
ComboBox, MainMenu, ListBox,
CheckBox, PictureBox, MenuStrip,
RadioButton, and MonthCalendar.
Label
• As the name implies, Label
objects are normally used
to provide descriptive text
• The actual text caption that or labels for another
appears on the Label control object control. They can also be
is placed there using the Text
property.The TextAlign property used to display information
enables you to position the caption at run time. Using Visual
within the label control area.The
Label object can be programmed to Studio, you can drag and
be visible based on run time drop the Label object onto
dynamics using the Visible
property.By default, the Visible your form.After it is added,
property is set to true.
you can set its properties to
customize it for your
application.
Textbox
• The TextBox control object,
can be used to enter data or
display text during run time.
• This is the probably the most
commonly used control
because it can be used for
both input and output.
• Like most other objects of
the Control class, the Text
property is used to get or set
the string value in the
control.
Button
• Button objects are added to
your form to increase
functionality.
• They enable a user to click a
button to perform a specific
task.When it is clicked by a user,
the event-andler method is
automatically called up—if the
button has an event-handler
method—and is registered as an
event to which your program is
In addition to Labels, Textbox, Buttons planning to respond.
You can also use other control tools in • You place code in the event-
the Toolbox such as ComboBox, handler method to perform any
action you choose.
RadioButton, PictureBox, CheckBox,
and others, according to your
Application needs.
Control Properties and Method
Properties
• The Properties
window is used to
view and change the
design time properties
and events
of an object.
Control Properties and Layout
• This section overviews properties that are
common to many controls. Controls derive
from class Control (namespace
System.Windows.Forms).
Event
• Normally, a user interacts with an app’s GUI to indicate the
tasks that the app should perform.
• For example, when you write an e-mail in an e-mail app,
clicking the Send button tells the app to send the e-mail to
the specified e-mail addresses. GUIs are event driven.
• When the user interacts with a GUI component, the
interaction—known as an event—drives the program to
perform a task.
• Common events (user interactions) that might cause
an app to perform a task include clicking a Button, typing
in a TextBox, selecting an item from a menu, closing a
window and moving the mouse.
Event Handling
• Event can be done by
double-clicking on the
actual Button object in the
Form Designer.
• Another option is to display
all the events using the
lightning bolt on the
Properties window and
then double-click on the
Click event.
• Example of event by clicking the button
Enjoy With GUI
First Application
• Starting the program
Select FILE > New
Project… or click the
New Project… link on
the Start Page, the New
Project dialog will
displays.
New Project for GUI Apps
Designing the form
• To start designing the
program interface, select
one of the tools in the Label and
toolbox then click on the Textbox are
Form and drag from top designed with
to bottom diagonally. It mouse (click
also can be set by and drug)
selecting the tools (label,
textbox, button, etc) and
clicking on the Form
area.
Control (tools) and Properties
• Font : Time New Roman, 15 pt, Italic
• BackColor : Green
• Forecolor : Red
• Text : Application
NOTE:
All control can be canged their
property in Properties Tools
Case Study :
Bonus Calculator
• An electronics distributor employs a
marketing employee. The employee is given a
basic wage of 1000000. The employee will get
15% bonus from the sale. Make an Application
with C # language using MS Visual Studio 2010
to calculate the total salary of the company's
marketing employees.
Variable Identification
• Basic Wage : Double
• Bonus : Double
• Total Wage : Double
Tabel Of Tool Usage
Interface Design
• Basic Interface • Ready Interface
Scripting
• Scripting is a term where a • Event dengan metode
programmer writes the source
code to make an application
Klik biasanya diterapkan
work according to the pada tombol "Button".
programmer's request that has Untuk itu, Klik tombol
designed the program. "Compute".
• Untuk menulis kode sumber
(kode program), programmer
harus menentukan event yang
diinginkan. Dalam contoh kali
ini, event yang digunakan
adalah Event dengan methode
Klik.
Event and Methode
• Metode Click yang diberikan • Methode, bisa saja dalam
untuk tombol "Cumpute." bentuk Click, Press,
• Metode Click tersebut diterapkan Change, Move, Drag, dan
kepada kotak "Total Wages."
Dimana kotak "Total Wages" akan
metode lainnya.
menampilkan Event apa. • To write the code, click
• Kira-kira maksudnya begini, Apa the "Compute" button.
yang terjadi pada kotak "Total
Wages" jika tombol "Compute" di
tekan (Click) melalui Mouse.
• Keadaan inilah yang disebut
dengan "Event". Yaitu apa yang
terjadi pada suatu objek jika
suatu "Methode" diterapkan
pada suatu Objek tertentu.
Button1_Click
Step 3 : Coding
Step 1 : Designing
Coding
So whatever is set as
the property name, it is
used in coding.
“Clear Form” Button
• "Clear Form" button is designed to erase the
form. It is also take "Click" methode like
"Compute" button. When that button is
clicked so all boxes will clear.
• The basic code for erasing the form such as
following script (see to the Figur).
TextChanged Event Handling
• "Event Handling" is indentical with Methode.
• Methode is styles of "Event Handling." What it is
based on methode Click, methode Press
(Keyboard), Moving Focus through Mouse or
Keyboard and many other methode which
provided on Microsoft Visual Studio C# (2010).
• TextChanged is methode where an object will
perform something depend on a command
written.
Advanced..
• In this example the methode will apply to
"Sales Bonus" box. Where it is display output
requested.