Click here to Skip to main content
6,822,123 members and growing! (17,642 online)
Email Password   helpLost your password?
Desktop Development » Miscellaneous » General     Intermediate License: The Code Project Open License (CPOL)

ActionLists for Windows.Forms

By Serge Weinstock

Implementation of Delphi's ActionList for Windows.Forms
C#, Windows, .NET1.0, Dev
Posted:2 Mar 2002
Views:116,696
Bookmarked:77 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
56 votes for this article.
Popularity: 7.65 Rating: 4.38 out of 5
1 vote, 2.9%
1

2
1 vote, 2.9%
3
3 votes, 8.8%
4
29 votes, 85.3%
5

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.
  3. Drag an ActionList on the dialog
  4. Edit the property Actions of the new ActionList. Add a new Action and set its properties.
  5. Select the action in the component editor and add an EventHandler for the Execute and Update events.
    private void OnUpdateFind(object sender, System.EventArgs e)
    {
    	((CDiese.Actions.Action)sender).Enabled = _text.TextLength > 0;
    }
    
    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

Latest updates

  • 4th March 2002
    • First release
Serge .

License

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

About the Author

Serge Weinstock


Member

Occupation: Web Developer
Location: United Kingdom United Kingdom

Other popular Miscellaneous articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 21 of 21 (Total in Forum: 21) (Refresh)FirstPrevNext
GeneralFYI There is a commercial and more complete implementation PinmemberJeremy Thomas2:43 2 May '08  
QuestionRegarding short cut keys Pinmembermelbjay19:35 23 Mar '06  
GeneralSomething similar on MSDN PinmemberEric Engler14:59 21 Mar '06  
GeneralShortcut lost Pinmemberdonlelel5:42 28 Feb '06  
GeneralAmazed it had to be written. PinmemberTony J ...4:07 22 Feb '06  
GeneralThanks PinmemberDidier Vaudène4:34 11 Mar '05  
GeneralExecuting action from code PinmemberAleksei Guzev19:46 17 Jan '05  
GeneralMenuItems, Actionlists and CloneMenu... Pinmembertimmc6:48 5 Dec '03  
Generalin VB ? Pinmemberbismark11:58 20 Oct '03  
GeneralWhy ? Pinmemberchy6111:04 6 Aug '03  
GeneralSetting Action to none causes crash PinsussPatrick Philippot6:01 3 Aug '03  
GeneralRe: Setting Action to none causes crash PinsussPatrick Philippot6:31 3 Aug '03  
GeneralShortcut Key PinmemberDubravko Ostoic22:16 2 Feb '03  
GeneralRe: Shortcut Key PinmemberSerge Weinstock0:46 4 Feb '03  
GeneralNicely Done PinmemberEd Gadziemski5:40 1 Oct '02  
GeneralA good Control Pinmemberzjwuweim18:01 31 Aug '02  
GeneralUsing ActionList with VSNetToolbar Pinmemberalexis15:05 25 Apr '02  
GeneralRe: Using ActionList with VSNetToolbar Pinmemberpphilippot2:39 3 Aug '03  
GeneralRe: Using ActionList with VSNetToolbar PinmemberAlexis Smirnov6:31 4 Aug '03  
GeneralFinally something interesting Pinmemberokigan7:37 5 Mar '02  
GeneralGreat... PinmemberRay Hayes6:50 4 Mar '02  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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

PermaLink | Privacy | Terms of Use
Last Updated: 2 Mar 2002
Editor: Chris Maunder
Copyright 2002 by Serge Weinstock
Everything else Copyright © CodeProject, 1999-2010
Web19 | Advertise on the Code Project