Code Review - comments welcomed
-
Hi all. I'm new at this and I'm looking for critical comments (on style too) so I can do it better the next time. I designed the following code trying to incorporate as many lessons as possible. Assumming my application consists of a main menu, a main toolstrip, and a main tabbed work area - I wanted an easy way to enable/disable main menu items or hide/display toolstrip button items --- depending on the current tab. My first attempt was a spider web of if statements. Then I decided on this approach - defining conditional (contextural) controls in a tabular fashion (getlistConditionalControls). Since some conditional controls may be disabled/hidden for several tabs, the 1st parameter is a bitwise sum of affected tabs. The 2nd parameter defines which property to affect (enabled or visible) - I would like to do away with this because I think I can test the referenced object (3rd parameter) for either ToolstripMenuItem or ToolstripButton. In my case all main menu items are enabled/disabled and toolstrip buttons are hidden/dislayed. Any help here? The last parameter is the alternate ToolTipText to inform the user as to why this control might be disabled (main menu items only). Only conditional controls need to be listed here. All comments and better ideas welcomed. Thanks
Public Class uxcMainFrm Private ConditionalControlItems As New ArrayList ' List of Conditional Controls Private Enum eProp As Integer enabled = 0 visible = 1 End Enum ' Private Sub uxcMainFrm_Load(....) Handles MyBase.Load Call getlistConditionalControls() ' Define Conditional Controls Call displayConditionalControls() ' Disable or Hide Controls Based on Cur Tab End Sub ' Private Sub uxcMainTabs_SelectedIndexChanged(....) Handles uxcMainTabs.SelectedIndexChanged Call displayConditionalControls() ' Disable or Hide Controls Based on Cur Tab End Sub ' Private Sub getlistConditionalControls() ' Toolstrip Buttons Call defineConditionalControl(6, eProp.visible, uxExpandBtn) ' Tabs #2 & #3 Call defineConditionalControl(3, eProp.visible, uxCollapseBtn) ' Tabs #1 & #2 ' .... and so on ' ' Main Menu Items Call defineConditionalControl(4, eProp.enabled, uxCreateMnuI, "To Enable: Select This or That") Call defineConditionalControl(6, eProp.enabled, uxRotateMnuI, "To Enable: Select This or That") ' .... and so on End Sub