Windows Form Applications 101 - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Windows Form Applications 101

Description:

So like variables, we want the names to have meanings that make sense ... If the button is used to calculate a total, then a possible name for the button would be: ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 24
Provided by: stephanyco
Category:

less

Transcript and Presenter's Notes

Title: Windows Form Applications 101


1
Windows Form Applications 101
  • Creating Windows Form Applications
  • The Basics
  • Stephany Coffman-Wolph
  • 2/9/09

2
GUI
  • GUI Graphical User Interface
  • Allows the user to interact visually with a
    program
  • This is the make it pretty part

3
Building GUI
  • GUI's are built from GUI controls
  • Also known as components or widgets (i.e., window
    gadgets)
  • Objects that can display information on the
    screen or enable users to interact with an
    application via the mouse, keyboard or other form
    of input
  • Basic Examples
  • Label, TextBox, Button, CheckBox ComboBox, ListBox

4
Windows Forms
  • Used to create the GUI's for programs
  • Is a graphical element that appears on the
    desktop (dialog, window, etc)

5
Component
  • Is an instance of a class that implements the
    IComponent interface
  • Remember interfaces from the polymorphism
    material they define what operations can happen
    but not how they are performed
  • Controls are components
  • Some have graphical representation (i.e., Form,
    Button, Label)
  • Others do not (i.e., Timer)

6
Commonly Used Types of Controls
  • Buttons
  • Textboxes
  • Labels
  • ListBox
  • CheckBox

7
Toolbox
  • The Controls and Components of C are found in
    the C Toolbox
  • They are organized by functionality
  • To add a component to a Form, select that
    component from the toolbox and drag it onto the
    Form

8
Using the Toolbox
  • The toolbox is located on the left-hand side of
    the Visual Studio screen
  • Click on the control you want to add and drag it
    to the form

9
Control Properties and Methods
  • Each control has properties (and some methods)
  • Some example properties
  • Enable
  • Font
  • Text
  • Visible
  • Some example methods
  • Hide
  • Select
  • Show

10
Editing the Properties
  • Click on the control you want to change the
    properties of (i.e., the name, what is displayed,
    etc)
  • You can make these changes in the properties
    window located on the bottom right

11
Naming Controls
  • By default in C, controls/components names are
    button1, label1, textbox1, etc.
  • However, these names are not very descriptive
  • So like variables, we want the names to have
    meanings that make sense
  • There are lots of ways to handle naming of the
    controls/components

12
Start the control name with...
  • Control
  • Button
  • TextBox
  • ListBox
  • Label
  • SaveFileDialog
  • Begin name with
  • btn
  • txt
  • lbox
  • lbl
  • sfd

13
Control Name Examples
  • If the button is used to calculate a total, then
    a possible name for the button would be
  • btnCalcTotal
  • If the textbox allows the user to enter their
    name then a possible name for the textbox might
    be
  • txtEnteredName

14
Event Handling
  • When a user interacts with a form this causes an
    event to occur (i.e., click a button, type in a
    textbox, etc)
  • These events signal that certain code should run
    and perform some sort of action
  • All GUI controls have associated events
  • Event Handler method that runs after an event
    occurs
  • Event Handling the overall process of
    responding to events

15
Clicking a Button Event Handler
  • The following code is for a button named btnQuit
  • When the button is clicked, the form closes
  • private void btnQuit_Click(object sender,
    EventArgs e)
  • this.Close()

16
How to write code for an event...
  • Once the control is on the form and you have
    edited the properties, double click the control
  • You were is design view
  • This will show you the code for the form
  • You are now in code view

17
Fun with Textboxes
  • A textbox is an area in which text can be
    displayed or users can type in text
  • A password textbox is a textbox that hides the
    information entered by the user
  • Are these different controls?
  • No! A textbox is simply a textbox
  • Password textbox is a normal textbox but with the
    property UseSystemPasswordChar set to true
  • (false is the default setting)

18
Example Log-in Screen
  • Drag Two Label controls onto the form
  • Use the properties to change the default names
  • Drag Two Textbox controls onto the form

19
Making the Textbox for Password
  • Click on the second of the two textboxes
  • Find the UseSystemPasswordChar Property in the
    Properties and change to true

20
How to Get Info Out of Textbox
  • OK, so lets say your textbox is named txtUserName
  • To get information a user typed into a textbox
    you use the following
  • string userName txtUserName.Text
  • Display information into the textbox you use
  • txtUserName.Text my string...
  • Make the textbox be empty
  • txtUserName.Text

21
Multiple Forms?
  • Can you have multiple forms?
  • Yes!
  • How is this accomplished?
  • By passing the form reference during a call to
    the constructor...
  • Similar to passing variables or objects when
    dealing with classes, etc

22
Let's Begin with a simple Form1
23
Code for FormLogin
Write a Comment
User Comments (0)
About PowerShow.com