|
-
February 11th, 2010, 11:28 AM
#16
Re: Feels like too many If's!
Personally, I think the approach is incorrect (even with the improvement of the hash).
I believe you should separate the functionality of the picture box from the data. In other words, if the picture box toggles between red and black - wire that up separately from any data. Then expose a way to determine the state of the picture box.
I would probably create a user control that handles the picturebox toggling from red to black and expose an event (let's call it StateChanged) that gets sent when the user toggles the picturebox. In the event I would pass an Id that represents (an instance) of the control and also pass the toggle state (red or black).
Within the form I would create several custom controls and wire up the StateChange event in each of the controls to the same event handler. In the event handler I would change the state in the hash table based on the Id and state value.
This might sound like a bit of work, but in the end you'll get a cleaner implementation with a good separation of UI logic and data. The nice thing about this approach is that it lets you focus on just one aspect of the problem at a time rather than solving them both at once.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|