Kelvin Hilton - PowerPoint PPT Presentation

1 / 47
About This Presentation
Title:

Kelvin Hilton

Description:

A Control collection referencing any Controls contained within the control itself ... This will be in the .Designer.cs file. 27. The Controls Collection ... – PowerPoint PPT presentation

Number of Views:90
Avg rating:3.0/5.0
Slides: 48
Provided by: admi73
Category:
Tags: hilton | kelvin

less

Transcript and Presenter's Notes

Title: Kelvin Hilton


1
Developing a basicPocketPC Application
  • Kelvin Hilton
  • k.c.hilton_at_staffs.ac.uk

2
Objectives
  • Introducing Windows Controls
  • Properties
  • Methods
  • Events
  • Working with Controls
  • Responding to the user

3
Introducing Windows Controls
4
The Default Application
  • By default an application will have

A Caption bar containing the ok (or X) button,
the Windows icon for accessing the Start Menu,
default display items such as the time A single
client area region (empty) A command bar
5
Windows Controls
  • Many Windows applications are Form (or Dialog)
    based
  • Interaction is via items such as text boxes,
    buttons, scrollbars, etc
  • In MS development these are called Controls
  • .NET libraries provide the common controls
  • Can create custom controls

6
Controls Key Concepts
  • Forms themselves are derived from the Control
    class

7
Controls Key Concepts
  • All Controls share a core set of features and
    characteristics (often called capabilities)
  • Capabilities are defined by
  • Properties
  • Methods
  • Events
  • As well as defining their own for Control
    specific functionality

8
Properties
  • Can be thought of as the data members of a class
  • Can be any primitive type
  • int
  • double
  • boolean
  • Can be an instance of a class
  • String
  • Customer
  • Use the OO concept of accessors and mutators
    though implicitly

9
Properties - Example
This Form contains a Panel Control which in turn
contains a Button Control.
  • Panel
  • Button
  • Form
  • How do can you identify which Properties are
    associated with a Control?

10
Properties - Example
  • In the Properties dialog select the Properties
    filter.
  • Select the Control.
  • The items listed will now be all the default
    Properties associated with the Control.

Note The tip at the bottom of the dialog
provides a brief description of the purpose of
the property.
11
Properties - Example
  • Can be thought of as the data members of a class
  • Can be any basic type
  • Use the OO concept of accessors and mutators
    though implicitly
  • To protect a data member of a class from being
    accidentally changed we make it private.
  • To allow it to be changed we provide get
    (accessor) and set (mutator) methods inside a
    special block of code consisting of the property
    name as it will appear outside the class and a
    return type.

12
Properties - Example
  • Whenever we want to get the value of the property
    we just use the name.
  • someString myobj.Name
  • Whenever we want to change the value of the
    property we just use the name.
  • myobj.Name someString

Note value is a parameter that is automatically
passed to the call to set. This means you can
test it before assignment if needed!
13
Properties - Example
MS classes hide the implementation of the
accessors and mutators for default class
properties.
I
To change a property setting at design time.
  • Select the property and enter the required
    value(s).
  • Select the Control.

To change a property programmatically
Remember C is a typesafe language this means
that every value you try to assign will be
checked by the compiler. If your value is not of
a type acceptable to the property you will get a
compiler error!
14
Properties
  • Control class blueprints common properties for
    Windows controls
  • Location
  • Minimal state data such as visible, enabled, etc.
  • Associated data bindings
  • A Control collection referencing any Controls
    contained within the control itself
  • All the accessors and mutators for these are
    provided for us by the C class

15
Methods
  • As in Java, C, Smalltalk, etc. methods are the
    verbs of a class
  • The .NET CF classes have the minimum necessary to
    support the default functionality of the control
  • Special case of method called an Event

16
Events
  • Something that happens (a notification) within an
    object in which other objects may have an
    interest
  • Button click
  • Text change
  • Mouse move
  • Connection to a network
  • Connection to a data source
  • Interested objects process the Event using an
    Event Handler method
  • Event-based programming is the standard paradigm
    for GUI environments

17
Events - Example
Our example application with its three controls.
  • Panel
  • Button
  • Form
  • How do can you identify which Events are
    generated by a Control?

18
Events - Example
  • In the Properties dialog select the Events filter.
  • Select the Control.
  • The items listed will now be all the default
    Events generated by the Control.

Note The tip at the bottom of the dialog
provides a brief description of what causes the
Event to be fired.
19
Events - Example
  • For all standard Controls the Event generating
    code is hidden in the class definition and
    generated automatically
  • You can write your own Event generation code for
    Custom Controls
  • Normally just implement the appropriate Handler

This is an example of the skeletal code for a
Button Click Event Handler.
All Event Handlers have the same parameters.
Object is the source object that has
generated the Event.
EventArgs May contain information associated
with the Event. For example a Mouse Move Event
will create an object derived from EventArgs
containing the current coordinates of the cursor.
20
Events - Example
The name of the Event Handling method is up to
the developer. MS default format is to have the
Name of the Control followed by an underscore and
then the name of the Event.
I
21
Events - Example
This is just as legal.
How will the application know which Event Handler
is servicing a particular Event?
Just enter the Handler method name against the
appropriate Event for the control.
  • Can this be done programmatically?

22
Events - Example
Actually it is being done programmatically for
you. When you enter the Handler method name a
line of code is entered in the .Designer.cs file.
Does this mean Click is a data member of a
Control class?
Yes its is an instance of special class called a
delegate, these are classes that can only be used
to reference methods.
23
Controls - Summary
  • Proficiency in Windows Form/Dialog based
    programming is mostly about familiarising
    yourself with the P,M,Es of the default Controls
  • Only if a Control does not have the
    behaviour/attributes you require is there a need
    to customise

Remember the CF does not implement all of the
P,M,Es of the desktop. However, unfortunately
the Visual Studio Property dialog (and
IntelliSense) can list properties/events which
are not present in the CF version. You code will
compile, the statement will just be ignored at
runtime!
24
Working with Controls
25
User Input Free form
  • The TextBox is the principal control for
    capturing free form user input
  • TextBox can be single line multiline masked

Note Pocket PC does not support 3D
controls. Limited font support. Default text
value is same as name value.
26
User Input Free form
  • Declaration
  • Default definition
  • How does the control get added to the Form?

This will be in the .Designer.cs file
27
The Controls Collection
  • All Pocket PC Forms have a member variable of
    type ControlCollection
  • Collections are a type of dynamic memory storage
  • Used extensively
  • Controls, List Items, Tab Pages
  • Three key methods
  • Add to add an item to a collection
  • Remove to remove an item from a collection
  • Contains to test if a collection contains the
    specified item
  • Indexed from 0

28
The Controls Collection
1. Form is created the Controls member is empty.
2. A control is added to the Form. Its index in
the Controls collection is 0.
3. Another control is added to the Form. This
now has the index 0 in the controls collection.
29
The Controls Collection
  • How is it possible to add a textBox and a button
    to the same collection?

Windows controls share a common hierarchy thus a
Control collection stores items as control types
(this will mean casting may be required when
working with controls via the collection).
30
Accessing a Forms Control Collection
  • Adding a Control

We start with the container of which the
ControlCollection is a member. Here this is the
reference to the Form class we are working with.
This is the Name of the ControlCollection
member. In the .NET classes that contain such a
member its name is always Controls.
Now the call to the Add member method of the
ControlCollection class.
Add takes an object of type Control (or a
subclass) as an argument. Here we are adding a
TextBox Control which is itself a member of the
Form class we are working with.
31
Identifying a Control on a Form
  • How to identify a Control in a ControlCollection
  • This Form contains 5 controls.
  • a label - a panel
  • a textbox - a combobox
  • a button

Note the textbox property multiline has been set
to true and the size increased to allow us to
display a number of lines without the need to
scroll. The following program code placed in the
button1 Click Handler outputs in the TextBox all
of the Controls in the order they are stored in
the ControlCollection.
32
Identifying a Control on a Form
  • Line by line

Explanation of the code
33
Identifying a Control on a Form
  • Piece by piece

Control object
34
Identifying a Control on a Form
  • Piece by piece

Control Name String
Control Name String\r\n
35
Identifying a Control on a Form
  • Result of the program code

Why does the list not include the label and the
textbox? A tutorial task!
Note the code below is a more reliable (and
consistent) way of working with collections.
However this approach should only be used to read
from and not manipulate a collection.
36
Caution When Using Controls
  • Consider

Simple form created using the IDE and default
Control Names
  • Is there a potential problem here?

37
Responding to the User
38
Message Boxes
  • All Pocket PC applications are single screen so
    we cannot use standard Window communication
    devices such as dialog boxes
  • However, we can use Pop Up Message Boxes
  • On PPC all Message Boxes are modal within the
    application

39
Available Message Box Types
  • C CF supports 3 types
  • In .NET CF Message boxes are created from a
    static class
  • Use the show method in C
  • Can contain up to 1024 characters

1. Text only. The ok button is provided by
default.
2. Text and Caption only. The ok button is
provided by default.
3. Text and Caption only. Selection of buttons
one set as default and an icon.
40
Creating a Message Box
Type 1 Text only
Type 2 Text and caption only
Type 3 Text, caption, buttons, icon, default
button
41
Creating a Message Box
Default .NET CF options for the MessageBoxButtons
argument
42
Creating a Message Box
Default .NET CF options for the MessageBoxIcon
argument
43
Creating a Message Box
Default .NET CF options for the
MessageBoxDefaultButton argument
If number of buttons and default button selection
do not match, i.e. there are only 2 buttons and
button 3 is specified then the default will be
the first button.
44
Using a Message Box
  • Processing the result from a Message Box

When a MessageBox closes it returns a value based
on the button pressed. These are returned as a
DialogResult value. These are
45
Using a Message Box
We can test the returned value and branch based
on the result
46
Recap
  • Introducing Windows Controls
  • Properties
  • Methods
  • Events
  • Working with Controls
  • Responding to the user

47
Questions ?
Write a Comment
User Comments (0)
About PowerShow.com