21 - Handling Visio Events

3 4

An event is an action or occurrence, often generated by a user, that your program might respond to. In Microsoft Visio, events can result from user actions such as opening or closing documents, dropping or deleting shapes on the drawing page, editing the text of shapes, and altering shape formulas. Knowing that such events have occurred can be extremely useful because it allows you to program your solution to respond to user actions that can otherwise be difficult to predict.

You can handle events either programmatically or by using Visio formulas. As with any Visio solution, you should start by putting as much of the functionality as possible in formulas. For details about handling events using formulas, see Chapter 7, Enhancing Shape Behavior.

Visio provides two separate ways to handle events from your program:

  • In Microsoft Visual Basic for Applications (VBA) or Microsoft Visual Basic programs, the simplest approach is to use the WithEvents keyword to declare object variables that can receive events. This is called writing code behind events.
  • You can create Visio Event objects that can run an add-on or advise your program that an event has occurred. This technique can be used from any development environment. (In versions of VBA or Visual Basic earlier than 5.0, this was the only means of handling Visio events through Automation.) You can also set event filters to tailor the events that your solution listens to, and prevent many of the events that you want to ignore from entering the event queue.

For details about handling events in a C++ program, see Chapter 28, Programming Visio with C++.



Developing Microsoft Visio Solutions 2001
Developing Microsoft Visio Solutions (Pro-Documentation)
ISBN: 0735613532
EAN: 2147483647
Year: 2004
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net