Click here to Skip to main content
15,886,106 members
Articles / Programming Languages / C#
Article

ActionLists for Windows.Forms

Rate me:
Please Sign up or sign in to vote.
4.79/5 (39 votes)
2 Mar 2002CPOL2 min read 181.1K   4.3K   89   24
Implementation of Delphi's ActionList for Windows.Forms

Introduction

The .Net framework is really a nice framework, but as a programmer coming from the MFC world, I really miss some features like the ON_COMMAND/ON_UPDATE_COMMAND_UI mechanism.

This mechanism allows the decoupling of the UI and the code associated to it. It allows:

  • to automatically share the code between menus, toolbars, buttons and other controls.
  • to reduce the amount of code needed for updating the UI.
  • to enable/disable controls according to conditions not related to the UI (for example a connection to a database).

Unfortunately, the ON_COMMAND/ON_UPDATE_COMMAND_UI mechanism is a message base mechanism which strongly relies on a specific message routing architecture. This mechanism can be reproduced in the .Net environment but it is far from being a pratical solution in a RAD environment. A nice alternative is the ActionList component provided by Delphi.

An ActionList is a collection of Actions. Each Action is itself a component associated to a given task. An Action provides the framework for:

  • excuting the task in response to an UI event.
  • enabling/disabling, checking/unchecking the controls related to the task according to some conditions.
Furthermore, this mechanism can be extended in order to:
  • set the text of the controls.
  • set the help text of the controls.
  • show/hide the controls.
  • set the icons associated to the controls.
  • set the shortcut associated to the task.

Adding actions to your project

This a simple example based on the Find Dialog of the demo application. We will add an action wich will be associated to the Find button.

  1. Open your dialog in Design Mode.
  2. Add the components of the CDiese library to the Toolbox.
    Image 1
  3. Drag an ActionList on the dialog
    Image 2
  4. Edit the property Actions of the new ActionList. Add a new Action and set its properties.
    Image 3
  5. Select the action in the component editor and add an EventHandler for the Execute and Update events.
    Image 4
    C#
    private void OnUpdateFind(object sender, System.EventArgs e)
    {
    	((CDiese.Actions.Action)sender).Enabled = _text.TextLength > 0;
    }
    C#
    private void OnFind(object sender, System.EventArgs e)
    {
    	RichTextBoxFinds mode = RichTextBoxFinds.None;
    
    	if (_bCase.Checked)
    	{
    		mode |= RichTextBoxFinds.MatchCase;
    	}
    	....
    	_RTF.Select(sel, _text.Text.Length);
    	_RTF.ScrollToCaret();
    }
  6. Associate the action to the Find button
    Image 5

Latest updates

  • 4th March 2002
    • First release
Serge Image 6.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
NewsTutorial Pin
George I. Birbilis6-Jan-12 12:02
George I. Birbilis6-Jan-12 12:02 
Questionassign action list in runtime Pin
Ali Habib10-Oct-11 22:18
Ali Habib10-Oct-11 22:18 
GeneralMy vote of 5 Pin
Ali Habib10-Oct-11 1:49
Ali Habib10-Oct-11 1:49 
GeneralFYI There is a commercial and more complete implementation Pin
Jeremy Thomas2-May-08 1:43
Jeremy Thomas2-May-08 1:43 
QuestionRegarding short cut keys Pin
melbjay23-Mar-06 18:35
melbjay23-Mar-06 18:35 
GeneralSomething similar on MSDN Pin
Eric Engler21-Mar-06 13:59
Eric Engler21-Mar-06 13:59 
GeneralShortcut lost Pin
donlelel28-Feb-06 4:42
donlelel28-Feb-06 4:42 
GeneralAmazed it had to be written. Pin
Tony J ...22-Feb-06 3:07
Tony J ...22-Feb-06 3:07 
GeneralThanks Pin
Didier Vaudène11-Mar-05 3:34
Didier Vaudène11-Mar-05 3:34 
GeneralExecuting action from code Pin
Aleksei Guzev17-Jan-05 18:46
Aleksei Guzev17-Jan-05 18:46 
GeneralMenuItems, Actionlists and CloneMenu... Pin
timmc5-Dec-03 5:48
timmc5-Dec-03 5:48 
Questionin VB ? Pin
bismark20-Oct-03 10:58
bismark20-Oct-03 10:58 
QuestionWhy ? Pin
chy6116-Aug-03 0:04
chy6116-Aug-03 0:04 
GeneralSetting Action to none causes crash Pin
Patrick Philippot3-Aug-03 5:01
sussPatrick Philippot3-Aug-03 5:01 
GeneralRe: Setting Action to none causes crash Pin
Patrick Philippot3-Aug-03 5:31
sussPatrick Philippot3-Aug-03 5:31 
GeneralShortcut Key Pin
Dubravko Ostoic2-Feb-03 21:16
Dubravko Ostoic2-Feb-03 21:16 
GeneralRe: Shortcut Key Pin
Serge Weinstock3-Feb-03 23:46
Serge Weinstock3-Feb-03 23:46 
GeneralNicely Done Pin
Ed Gadziemski1-Oct-02 4:40
professionalEd Gadziemski1-Oct-02 4:40 
GeneralA good Control Pin
zjwuweim31-Aug-02 17:01
zjwuweim31-Aug-02 17:01 
Smile | :) I'll look into your code as soon as I have more time....

GeneralUsing ActionList with VSNetToolbar Pin
alexis25-Apr-02 14:05
alexis25-Apr-02 14:05 
GeneralRe: Using ActionList with VSNetToolbar Pin
louis3-Aug-03 1:39
louis3-Aug-03 1:39 
GeneralRe: Using ActionList with VSNetToolbar Pin
Alexis Smirnov4-Aug-03 5:31
Alexis Smirnov4-Aug-03 5:31 
GeneralFinally something interesting Pin
Igor Okulist5-Mar-02 6:37
Igor Okulist5-Mar-02 6:37 
GeneralGreat... Pin
Ray Hayes4-Mar-02 5:50
Ray Hayes4-Mar-02 5:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.