Handling GUI element properties for each application state
I was thinking about centralizing this functionality by having a single method that takes an AppState argument, and it deals with changing properties of all GUI elements based on that argument. Every time the application changes its state (ready, busy, loading so partially busy, etc.), this function is called with the appropriate state (or maybe it's a bit field or something) and it does its magic ...
If I scatter the state change of the GUI elements all over the place, then it becomes very easy to forget that when the application is in a certain state, that other widget must be disabled there too, etc.
Any other ways to deal with similar things?
source to share
Emra,
Your idea is good. You need to constrain the government structure and this is the only way to provide a reliable interface. On the other hand, strictly adhere to the idea of "one function". Rather, follow its direction continuously by creating a function, and then gradually process all the attributes into one "setter" function. There are a few things to keep in mind on your way:
-
Use only one-way communication. Don't read the state from the governing bodies, because that is the source of all evil. Limit the number of properties read first and then the number of property entries.
-
You need to enable caching methodology. Make sure caching is not introducing property reading into the main code.
-
Leave only dialog boxes, just make sure that all communication with the dialog is done during opening and closing and not between them (as much as possible).
-
Implement wrappers for the most commonly used controls to provide a strong communication structure. Do not create any global control systems.
-
Don't use these ideas unless your user interface is really complex. In this case, using regular WinForms or JavaScript events will result in significantly less code.
-
The less code the better. Don't refactor unless you loose lines.
Good luck!
source to share
Yes, this is the most time consuming part of the GUI job to make a user-friendly application. Turn it off, turn it on, hide it, show it. To make sure all controls have correct states when insert / update / delete / select / deselect from screen.
I think this is where you say good programmer from bad programmer. A bad programmer has an active Save button when nothing has changed to save, a good programmer only includes a save button when there are things to save (just one example out of many).
I love the idea of a UIControlstate handler for this purpose.
Me.UIControlStates = UIControlstates.EditMode or something like that.
If this object has such an object, it can raise events when the state changes, and that's where we put the code.
Sub UIControlStates_StateChanged(sender as object, e as UIControlStateArgs)
if e.Oldstate=UIControlStates.Edit and e.NewState=UIControlStates.Normal then
rem Edit was aborted, reset fields
ResetFields()
end if
select case e.NewState
case UIControlStates.Edit
Rem enalbe/disable/hide/show, whatever
Case UIControlStates.Normal
Rem enalbe/disable/hide/show, whatever
Case UIControlStates.Busy
Rem enalbe/disable/hide/show, whatever
Case Else
Rem enalbe/disable/hide/show, whatever
end select
end sub
source to share
@Stefan:
I think we are thinking in the same direction, that is, to one piece of code that gets the ability to modify all the states of the widgets, and everyone else should cause such changes to it. Also, I presented a direct method call when you imagine how to raise / capture events. Is there an advantage to using events versus a simple method call?
source to share