controlling enablement of controls on winforms

J

Johan Jooris

Hi,

anyone who can link to patterns or documentation on controlling the
enablement of controls on winforms ?
(e.g. a specific button on the screen is enabled if current user has
permission to execute the underlying task and also if the form is in edit
mode)
Can this be done in a generic way ?
 
1

100

Hi Johan,
I think it's a shame that the framework doesn't support convenient way to
update buttons and menu items status.
It was so easy in MFC with UPDATE_COMAND_UI macros. Borland's VCL which is
more close to Windows Forms provides, since version 4 of Delphi and C++
Builder, a component called TActionList which works in the way similar to
MFC.
I wish in future Windows Forms to provide such a component.
However, the way MFC (and VCL) works is the framework call for update
buttons as a responce to windows idle processing and call for update a menu
item when the menu that owns the the item pops up.

You can use similar technique. Register event handler with Application.Idle
event. Event handler should be method of the form class that host the
buttons, which state you want to synchronize.
In the event handler body you have to go through all buttons you want to
update and set their Enabled properties according to the current state of
your application.
Using that you don't have to worry about when to update your buttons and you
don't spread update code all over the program . I use this for a long time
and it helps me to avoid *the spaghetti syndrome" my application would
suffer otherwise.

HTH
B\rgds
100
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top