ch09_Inside More Controls.pdf
(
402 KB
)
Pobierz
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Programming the .NET Compact Framework in C#
By Paul Yao & David Durant
Chapter 9
Inside More Controls
This chapter examines more Compact Framework controls, and other elements which are useful
for creating Compact Framework programs including menus, toolbars, and dialog boxes. This
chapter also introduces ControlPME, a tool which detects support for properties, methods, and
events in the standard Compact Framework controls.
[Comment 9.1]
Author's Note: In this review chapter C#-Specific Text is highlighted in YELLOW.
[Comment 9.2]
Detecting Support for Properties, Methods, and Events ................................................................. 1
A Tool: ControlPME............................................................................................................ 2
Compact Framework Controls in a Desktop Framework Program .................................... 3
Menus .............................................................................................................................................. 3
Program Menus .................................................................................................................. 6
Sample: ProgramMenu....................................................................................................... 9
Context Menus ................................................................................................................. 11
Sample: TextBoxClipboard............................................................................................... 11
The context menu................................................................................................ 12
Clipboard support in a text box............................................................................ 12
Grabbing events ............................................................................................................................ 15
Sub-Classing to intercept Win32 messages .................................................................... 17
Getting messages into managed code using the
MessageWindow
class ...................... 25
ToolBar and ImageList Controls .................................................................................................... 28
Toolbars............................................................................................................................ 29
Toolbar Buttons ................................................................................................................ 31
Image List Controls and Images....................................................................................... 32
Sample: Toolbar ............................................................................................................... 34
Dialog Boxes.................................................................................................................................. 39
Built-In Dialog Boxes ........................................................................................................ 39
Common File Dialog Boxes: File-Open and File-Save ....................................... 40
Sample: FileDialog .............................................................................................. 41
Creating Custom Dialog Boxes ........................................................................................ 43
Designing Pocket PC Dialog Boxes .................................................................... 44
Programming Custom Dialog Boxes ................................................................... 45
Fixing a Task List Problem .................................................................................. 46
Sample: DialogBoxes .......................................................................................... 47
Conclusion ..................................................................................................................................... 53
Detecting Support for Properties, Methods, and Events
Visual Studio .NET provides many features which help programmers create, debug, and
deploy Compact Framework programs. Woven into those features is knowledge of many aspects
of programming: syntax checking helps tag errors even before you build, automatic code
generation provides a starting point for your code, and IntelliSense shows available namespaces,
classes, and other type information to simplify your code development.
[Comment 9.3]
Chapter 9 – Inside More Controls
Page 1
9/10/2003
Copyright © 2003 Paul Yao & David Durant
Programming the .NET Compact Framework in C#
By Paul Yao & David Durant
And yet, support for Compact Framework controls is incomplete. In chapter 7,
Inside
Controls
, we introduce the expression "inherited does not mean supported." To minimize code
size and maximize performance, some of the properties, methods, and events (PMEs) which
controls inherit from the
Control
class
1
are not supported by every control. We provide details
of the support as we discuss each control, but that support may change in a future version of the
Compact Framework. In addition, owing to space constraints, this book does not cover all
Compact Framework controls. We asked ourselves how to solve these problems, and the answer
was immediately evident: we needed to create a tool to dynamically determine what each control
supports. We wrote a Compact Framework program, ControlPME, to test each control for support
of the various properties, methods, and events which are inherited from the
Control
class.
[Comment 9.4]
A Tool: ControlPME
ControlPME
makes a series of calls to test all of the properties, methods, and events which
each of the Compact Framework controls
2
inherit from the
Control
class. Based on the run-time
evidence which it collects, it indicates which PMEs are supported and which ones are not
supported. Figure 9-1 shows sample output, the events which the
Label
class supports. This tool
verifies that the Label class supports neither mouse nor keyboard events. Two other events are
shown to be supported, however: the
LostFocus
and
EnabledChanged
events. You can find
copy of this tool in the tools directory,
\YaoDurant\Tools
, on the CD which accompanies this
book.
[Comment 9.5]
Fig
ure 9-1 ControlPME displaying events
supported by the
Label
class
[Comment 9.6]
A few minutes with
ControlPME
reveals many interesting aspects of Compact Framework
controls. In particular, it should save you time by showing what support you can expect to receive
for a given control class. For example, this tool shows that only three controls support all of the
events inherited from
Control
:
DataGrid
,
Panel
, and
PictureBox
. It also shows how only
1
Fully qualified name:
Windows.Systems.Forms.Control
.
2
This tool does not show PMEs for the toolbar class, because something about that class causes
an exception when the program created the toolbar.
Chapter 9 – Inside More Controls
Page 2
9/10/2003
Copyright © 2003 Paul Yao & David Durant
Programming the .NET Compact Framework in C#
By Paul Yao & David Durant
one control class supports the
CreateGraphics()
method, namely the
DataGrid
.
[Comment
9.7]
Compact Framework Controls in a Desktop Framework Program
As we discuss in chapter 1, Architecture of the Compact Framework, a core design goal for
the Compact Framework is consistency with the desktop .NET Framework. One of the benefits of
this approach is that a Compact Framework program can run as a desktop framework program
3
.
Figure 9-2 shows our PME tracking tool running as a desktop framework program.
[Comment
9.8]
Figure 9-2 ControlPME displays events supported by the desktop label contro
l
[Comment
9.9]
If you compare the output of our tool when running under Windows CE (figure 9-1) with the
same output running on Windows XP (figure 9-2), you see that the desktop .NET Framework
does in fact treat a Compact Framework program as if it were a desktop .NET Framework
program. When our tool runs on the desktop, its tests are performed on desktop controls. The
desktop label control, for example, supports all of the events. The Compact Framework label
control, on the other hand, supports fewer than half of the events that it inherits.
[Comment 9.10]
Menus
Windows CE supports three types of menus
4
:
[Comment 9.11]
•
Start Menu
[Comment 9.12]
•
Program Menu
[Comment 9.13]
3
Running a Compact Framework program on desktop versions of Windows requires, version 1.1
of the .NET Framework.
4
The Pocket PC adds a fourth type of menu, the New menu on the Today screen. The Compact
Framework does not support this menu type. Adding an item to the New menu requires an in-
process COM DLL which supports a specific set of COM interfaces.
Chapter 9 – Inside More Controls
Page 3
9/10/2003
Copyright © 2003 Paul Yao & David Durant
Programming the .NET Compact Framework in C#
By Paul Yao & David Durant
•
Context Menu
[Comment 9.14]
The start menu holds a list of programs that a user can start running with a mouse-click (or a
stylus-tap). The start menu sits in one of two places, depending on the type of smart device. On a
Pocket PC, the start menu rests in the upper-left corner of the screen (see figure 9-3). As we
discuss shortly, a Pocket PC program menu sits on the bottom of the screen.
[Comment 9.15]
Figure 9-3 Start menu for Pocket PC
drops down from the top of the sc
reen
[Comment 9
.16]
On non-Pocket PC devices, the start menu resides in the lower-left corner of the screen. As
shown in figure 9-4, the start menu on this class of smart devices appears in the same place that
the start menu appears on desktop versions of Microsoft Windows.
[Comment 9.17]
Chapter 9 – Inside More Controls
Page 4
9/10/2003
Copyright © 2003 Paul Yao & David Durant
Programming the .NET Compact Framework in C#
By Paul Yao & David Durant
Figure 9-4 System menu for non-Pocket PC systems starts at the bottom and pops up
[Comment 9.18]
On a SmartPhone, with its very small screen typical of mobile phones, the start menu appears
when a user requests a list of programs. Figure 9-5 shows the start menu for a SmartPhone.
[Comment 9.19]
Figure 9-5 System menu for
SmartPhon
e
[Comment 9.20]
The single biggest difference between the user-interface of a PocketPC and the user-interface
of other Windows CE systems is in the arrangement of the start menu and of program menus. The
Pocket PC uses the exact opposite placement – system menu on top and program menu at the
bottom – from the placement used by non-Pocket PC Windows CE devices. On these non-Pocket
PC devices, the start menu is on the bottom of the screen and program menus are at the top of
program windows.
[Comment 9.21]
The Compact Framework has no programmatic support for the start menu, although a
Compact Framework program can be added to the start menu in the same way that any other
Chapter 9 – Inside More Controls
Page 5
9/10/2003
Copyright © 2003 Paul Yao & David Durant
Plik z chomika:
Lauviah666
Inne pliki z tego folderu:
AppA_HungarianForDotNETPrograms.pdf
(358 KB)
Ch01_Architecture.pdf
(459 KB)
Ch02_What Is a Compact Framework.pdf
(261 KB)
ch03_The .NET Type System.pdf
(220 KB)
Ch04_Calling Native Functions.pdf
(171 KB)
Inne foldery tego chomika:
C#
daniken
Exchange.2007.-.Ksiega.Eksperta._Berstrong_
Exchange.2007.-.Ksiega.Eksperta._ms_
Piekara_Jacek
Zgłoś jeśli
naruszono regulamin