Browse DevX
Sign up for e-mail newsletters from DevX


Control GUI Action in VB6 Using the Command Behavior Pattern

The Command Behavior pattern lets you encapsulate behaviors within a presentation layer, making it much easier to organize, track, undo, and invoke those behaviors however you like. It's a freeze-frame remote control for your GUIs.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

n real life, sequences aren't easy to control. Once something is set in motion it is difficult to manipulate discrete portions of that movement. And of course, in real life it's impossible to undo a movement. But in programming, sequences aren't so elusive. If you plan correctly, you can define actions and then control them however you like. And one very useful tool in doing so is the Command Behavior pattern. The Command Behavior pattern is a simple pattern to use. It is especially good at objectifying the concept of an action and an undo action. Converting an action into an object is also a very orderly way to ensure that each behavior converges on a single chunk of code that implements that behavior.

In this article we will investigate the uses of the Command Behavior pattern and we will have a little fun along the way. I added a ball image to a form and implemented commands that represent movements of the ball. Each ball command is placed in a stack permitting you to undo the ball movement or rewind all of the movements. After a bit of tinkering with this code you will see that converting presentation layer (GUI) behaviors into command objects makes it much easier to encapsulate, organize, track, undo, and invoke behaviors, using multiple metaphors, such as buttons and menus.

Thanks for your registration, follow us on our social networks to keep up-to-date