Partager via


Highlighter Sample

This sample demonstrates how to keep track of focus changes so that focused elements can be highlighted on the screen. The highlight is a simple colored rectangle, but it could be a magnifier window or some other tool to make the focused element more accessible.

For convenience and simplicity, the sample runs in its own window. A real-world application might run in the background.

Sometimes focus-changed events occur in rapid succession: for example, when the user rapidly moves the cursor down a menu. Also, when a complex element such as a list box receives the focus, generally two events are raised: one for the container receiving the focus, and one for the focused item within the container. To avoid flicker (rapid drawing and erasing of the highlight), the sample uses a timer. The timer is started, or restarted, whenever an event is received. Only when the timer reaches its interval is the highlight redrawn. Thus the response to an event becomes "pending" when the event occurs and is discarded if another event occurs before the timer interval has elapsed.

You can experiment with different timer intervals by using the slider.

This sample demonstrates a specific feature of the Windows Presentation Foundation (WPF) and, consequently, does not follow application development best practices. For comprehensive coverage of Windows Presentation Foundation (WPF) and Microsoft .NET Framework application development best practices, refer to the following as appropriate:

Accessibility - Accessibility Best Practices

Security - WPF Security

Localization - WPF Globalization and Localization Overview

Download sample

Building the Sample

  • Install the Windows Software Development Kit (SDK) and open its build environment command window. On the Start menu, point to All Programs, Microsoft Windows SDK, and then click CMD Shell.

  • Download the sample, usually from the software development kit (SDK) documentation, to your hard disk drive.

  • To build the sample from the build environment command window, go to the source directory of the sample. At the command prompt, type MSBUILD.

  • To build the sample in Microsoft Visual Studio 2005, load the sample solution or project file and then press CTRL+SHIFT+B.

Running the Sample

  • To run the sample from the build environment command window, execute the .exe files in the Bin\Debug or Bin\Release folder contained in the sample source folder.

  • To run the compiled sample with debugging in Visual Studio 2005, press F5.

See Also

Other Resources

UI Automation Events for Clients
Subscribe to UI Automation Events
UI Automation Clients for Managed Code