Introduction to Visual Basic.net 4

Embed Size (px)

Citation preview

  • 7/28/2019 Introduction to Visual Basic.net 4

    1/23

    User Interface Design1

  • 7/28/2019 Introduction to Visual Basic.net 4

    2/23

    DESIGNING USER INTERFACE

    Control are added onto the form to enables users to interact

    with the program.

    Controls are added onto the form using Visual Basic 6.0ToolBox.

    The user interface of a windows program usually includes :> Title or caption bar

    > Menus

    > Label boxes

    > Text boxes> Buttons

    > Windows

    > Scroll bars 2

  • 7/28/2019 Introduction to Visual Basic.net 4

    3/23

    TOOLBOX

    Label

    Frame

    CheckBox

    ComboBox

    HScrollBar

    Timer

    DirListBox

    Shape

    Image

    OLE

    PictureBox

    Textbox

    CommandButton

    OptionButton

    ListBox

    VScrollBar

    DriveListBox

    FileListBox

    Line

    Data

    Diagram 1.0 : Toolbox

    3

  • 7/28/2019 Introduction to Visual Basic.net 4

    4/23

    Text Boxes

    Use when you want the user to type some input or

    display output.

    Example :

    Use Text Property.

    Prefix namingtxt (txtTitle).

    Text Box

    4

  • 7/28/2019 Introduction to Visual Basic.net 4

    5/23

    Program Code For Text Boxes

    Example 1 :

    lblName.Caption = txtName.Text

    * Input from user enter into the text box is assigned tothe caption property oflblName.

    Example 2 :

    txtMessage.Text = Watson, come here

    *Display text in a text box during program execution,

    assign a literal to the Text property.5

  • 7/28/2019 Introduction to Visual Basic.net 4

    6/23

    Frames

    Use as containers for othercontrols.

    Example :

    Groups of option buttons or check boxes.

    Make form easierto understand.

    Prefix namingfra (fraColor).6

  • 7/28/2019 Introduction to Visual Basic.net 4

    7/23

    Check Boxes

    Allow the user to select (or deselect) an option.

    Example :

    In any group of check boxes, any numbermay beselected.

    Value property of a check box is set to 0 ifunchecked, 1 ifchecked, or2 ifgrayed (disabled).

    Prefix namingchk (chkBold).7

  • 7/28/2019 Introduction to Visual Basic.net 4

    8/23

    Program Code For Check Boxes

    * Set the initial value for check boxes :

    Example 1 :

    chkBold.Value = 1 Make box checkedchkBold.Value = 0 Make box unchecked

    Example 2 :

    chkBold.Value = Checked Make box checkedchkBold.Value = Unchecked Make box unchecked

    8

  • 7/28/2019 Introduction to Visual Basic.net 4

    9/23

    Option Buttons

    Use when only one button of a group may beselected.

    Example :

    Value property of an option button is set to True if

    selected or to False ifunselected. Prefix namingopt (optRed).

    9

  • 7/28/2019 Introduction to Visual Basic.net 4

    10/23

    Locate The Option Button

    Any option button placed directly on the form (not in

    a frame) function as single event.

    A group of option buttons inside a frame functiontogether.

    * The best method is to first create a frame and then create each option

    button inside the frame.

    * Must be careful to create the button inside the frame, dont create it

    on the form and drag it inside the frameits still belongs to the

    forms group, not the frames group.

    10

  • 7/28/2019 Introduction to Visual Basic.net 4

    11/23

    Program Code For Option Button

    * To make an option button appear selected initially :

    Example :

    optRed. Value = True Make button selected

    11

  • 7/28/2019 Introduction to Visual Basic.net 4

    12/23

    Images

    Control holds a picture.

    Enable to set an images Picture property to a file

    with an extension of.bmp, .wmf, .ico, .dib, .gif, .jpg,

    .emf, or.cur.

    Set Stretch property to True to make the picture

    enlarge to fill the control.

    Set Visible property to False to make the image

    disappear.

    Prefix namingimg (imgPicture).

    12

  • 7/28/2019 Introduction to Visual Basic.net 4

    13/23

    Program Code For Images

    * Make an image invisible at rum time.

    Example :

    imgLogo.Visible = False

    13

  • 7/28/2019 Introduction to Visual Basic.net 4

    14/23

    Setting a Border and Style

    Most controls can appear to be 3-dimensional or

    flat.

    Labels, text boxes, check boxes, option buttons and

    images all have an Appearance property.

    0 Flat or 1 3D.

    * To make a label or an image appear 3D, you must give it a

    border.

    * Set the BorderStyle to 1 Fixed Single.

    14

  • 7/28/2019 Introduction to Visual Basic.net 4

    15/23

    Shape Control

    Place shapes on a form :

    i) Rectangle

    ii) Squares

    iii) Ovals

    iv) Circles

    Example :

    Prefix namingshp (shpCircle). 15

  • 7/28/2019 Introduction to Visual Basic.net 4

    16/23

    Shape property

    Determine the shape by setting its Shape property :

    0 - Rectangle

    1 - Squares2 - Ovals

    3 Circles

    4 Rounded Rectangle

    5 Rounded Squares

    16

  • 7/28/2019 Introduction to Visual Basic.net 4

    17/23

    Line

    Draw line on a form.

    Example :

    Prefix naminglin (linLogo).

    Line

    17

  • 7/28/2019 Introduction to Visual Basic.net 4

    18/23

    ADDING CONTROLSONTHE FORM

    To use a control, double click on the specific control

    on the toolbox.

    You can control the number of objects in theToolbox but VB provides 20 intrinsic controls in the

    toolbox.

    18

  • 7/28/2019 Introduction to Visual Basic.net 4

    19/23

    DETERMININGTHE PROPERTIES

    Different controls have different set of property. Due

    to some controls that have long list; the Properties

    Windows have a scrollbar to move through the long

    list.

    You need not to define every single property for the

    controls. You only have to change what is required

    for the application designed. Visual Basic has set

    all of the properties to its default value.

    You only need to change the value when you wantit to be different from its default.

    19

  • 7/28/2019 Introduction to Visual Basic.net 4

    20/23

    NAMING CONTROLS

    Visual Basic provides a unique name for thecontrols such as Label1, Label2, Text1 andCommand1.

    The names are the controls names. Each controlhas a unique name that distinguishes it from othercontrols from the same object.

    For example, the The Average of Two Numbersapplication has more than one TextBox control.

    It is important to distinguish each Textbox on theform.

    20

  • 7/28/2019 Introduction to Visual Basic.net 4

    21/23

    DELETINGTHE CONTROLS

    If you wish to delete any of the controls from the

    form, you may do so at design time.

    Follow the steps in the box.

    i) Point the cursor on therequired control, which is

    on the form.

    ii) Click on the control and

    hit the DELETE key.

    21

  • 7/28/2019 Introduction to Visual Basic.net 4

    22/23

    Activity 1

    Your Name

    Message

    Red

    Green

    BlueBlack

    COLORBold

    Italic

    Underline

    STYLE

    Display

    Clear

    Print

    Exit

    Follow the sketch below to create the form :

    ImgLittle lblMessage

    ImgBig

    fraColor

    optRed

    optGreen

    optBlue

    optBlack

    fraStylechkBold

    chkItalic

    chkUnderline

    fraText

    txtName

    txtMessage

    cmdDisplay

    cmdClear

    cmdPrint

    cmdExit 22

  • 7/28/2019 Introduction to Visual Basic.net 4

    23/23

    Thank You

    23