Crad's .NET Blog

L'UGIblog di Marco De Sanctis
posts - 190, comments - 457, trackbacks - 70

Crad's Actions: How to use them

This is a small walkthrough on how to use Crad's Actions. Well... we start creating a new WindowsApplication Project in Visual Studio (for this tutorial I've chosen Visual C# Express Edition) and add an ActionList to the main form.

Step 1

Next, we can modify its Actions property adding our first Action object. In this example, I created a "New" action, giving its Text and Image properties (more featured properties are coming... ) the right values.

Step 2

Step 3

Now that we've got actNew object on our form, we can handle its Execute event, for example:

private void actNew_Execute(object sender, EventArgs e)
    MessageBox.Show("Congratulations, you just executed \"New\" action");

Next, we create a ToolStrip and a MenuStrip and we add some buttons and menuitem.

Next step is linking actNew to these Items: you can connect it to a Button, a MenuItem, a ToolStripMenuItem or to a ToolStripButton as well. Notice that when you associate actNew to a UI element, it's Text and Image properties (if applicable) are automatically set to action's ones.

Step 5

Step 6

Step 7

We can do the same for the ToolStripButton. Now if you build and execute the project, you'll notice that the action's Execute handler will be performed when you select "New" via toolbar or via MainMenu. But if you want to enable or disable this controls when a certain condition is verified? You can use actNew's Update event: for example... we add a checkBox and the following handler for this event:

private void actNew_Update(object sender, EventArgs e)
    actNew.Enabled = checkBox1.Checked;

The actNew_Update event handler is evaluated while application is on Idle state; when an action is disabled, so are all the controls linked to it.Moreover, you can use the ActionList's Enabled property to enable/disable all the actions of a form. Same is for Action's Checked property: every state change is forwarded to all the linked controls.

More features will be added in the near features, if you want to be notified, you can subscribe this feed.


powered by IMHO 1.3

Print | posted on giovedì 6 aprile 2006 17:47 |

Powered by:
Powered By Subtext Powered By ASP.NET