Click here to Skip to main content
15,916,600 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Trouble with Request.ServerVariables("LOGON_USER") Pin
jszpila13-Oct-05 10:08
jszpila13-Oct-05 10:08 
QuestionVBScripting Changing the Computer Name and Joining the Domain Pin
Bri4hire13-Oct-05 8:29
Bri4hire13-Oct-05 8:29 
AnswerRe: VBScripting Changing the Computer Name and Joining the Domain Pin
Dave Kreskowiak13-Oct-05 9:57
mveDave Kreskowiak13-Oct-05 9:57 
QuestionMessage Box Not Displaying Pin
jburkle13-Oct-05 8:03
jburkle13-Oct-05 8:03 
QuestionHow to turn off the Windows Default Beep from the VB Pin
icDavid13-Oct-05 7:45
icDavid13-Oct-05 7:45 
AnswerRe: How to turn off the Windows Default Beep from the VB Pin
Dave Kreskowiak13-Oct-05 8:08
mveDave Kreskowiak13-Oct-05 8:08 
GeneralRe: How to turn off the Windows Default Beep from the VB Pin
icDavid13-Oct-05 8:16
icDavid13-Oct-05 8:16 
GeneralCode Review - comments welcomed Pin
watagal13-Oct-05 7:06
watagal13-Oct-05 7:06 
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
    Private Sub defineConditionalControl(ByVal tabs As Integer, _
        ByVal prop As Boolean, ByRef control As ToolStripItem, ByVal altTooltip As String)
        '
        ConditionalControlItems.Add(New ConditionalControl(tabs, prop, control, altTooltip))
    End Sub    
    Private Sub displayConditionalControls()
        For Each ctrl As ConditionalControl In ConditionalControlItems
            ctrl.setDisplay(2 ^ uxcMainTabs.SelectedIndex)	' Convert Base0 Tab# to Bit Flag
        Next
    End Sub
end class
'
Public Class ConditionalControl
    Inherits ToolStripItem
    '
    Private _specTabs As Integer            ' Specified Tabs to chk for - Bitwise enum
    Private _Prop As Boolean                ' Which Property (0=Enable 1=Visible)
    Private _Control As ToolStripItem       ' Control Name
    Private _OrgTooltip As String           ' Control Original  TooltipText
    Private _AltTooltip As String           ' Control Alternate TooltipText
    '
    Public Sub New(ByVal specTabs As Integer, ByVal prop As Boolean, _
	ByRef oControl As ToolStripItem, ByVal altTooltip As String)
	'
        Me._specTabs = specTabs
        Me._Prop = prop
        Me._Control = oControl
        Me._AltTooltip = altTooltip
        Me._OrgTooltip = Me._Control.ToolTipText
    End Sub
    '
    Public Sub New(ByVal specTabs As Integer, ByVal prop As Boolean, _
	ByRef oControl As ToolStripItem)
	'
        Me._specTabs = specTabs
        Me._Prop = prop
        Me._Control = oControl
        Me._AltTooltip = ""
        Me._OrgTooltip = Me._Control.ToolTipText
    End Sub
    '
    Public Sub setDisplay(ByVal curTab As Integer)
        Dim bVisible As Boolean = Me._Prop
	'
        If curTab And Me._specTabs Then
            If bVisible Then
                Me._Control.Visible = True
            Else
                Me._Control.Enabled = True
                Me._Control.ToolTipText = Me._OrgTooltip
            End If
        Else
            If bVisible Then
                Me._Control.Visible = False
            Else
                Me._Control.Enabled = False
                Me._Control.ToolTipText = Me._AltTooltip
            End If
        End If
    End Sub
End Class


Thanks,
Karen

Nooobie to OOP and VB.Net 2005
QuestionUsing XP Visual Styles in multiple non-mdi windows forms Pin
jenkinsdjj13-Oct-05 6:42
jenkinsdjj13-Oct-05 6:42 
AnswerRe: Using XP Visual Styles in multiple non-mdi windows forms Pin
Dave Kreskowiak13-Oct-05 7:11
mveDave Kreskowiak13-Oct-05 7:11 
GeneralRe: Using XP Visual Styles in multiple non-mdi windows forms Pin
jenkinsdjj14-Oct-05 19:12
jenkinsdjj14-Oct-05 19:12 
QuestionBitwise Enumeration? Pin
watagal13-Oct-05 4:55
watagal13-Oct-05 4:55 
AnswerRe: Bitwise Enumeration? Pin
Briga13-Oct-05 5:02
Briga13-Oct-05 5:02 
GeneralRe: Bitwise Enumeration? Pin
watagal13-Oct-05 5:45
watagal13-Oct-05 5:45 
GeneralRe: Bitwise Enumeration? Pin
Briga15-Oct-05 3:47
Briga15-Oct-05 3:47 
GeneralRe: Bitwise Enumeration? Pin
Briga15-Oct-05 3:48
Briga15-Oct-05 3:48 
QuestionControlling sndrec32.exe Pin
jmachacek13-Oct-05 4:51
jmachacek13-Oct-05 4:51 
Questionprogrammatically changing the default windows cursor Pin
medicenpringles13-Oct-05 3:35
medicenpringles13-Oct-05 3:35 
AnswerRe: programmatically changing the default windows cursor Pin
jo0ls15-Oct-05 17:07
jo0ls15-Oct-05 17:07 
QuestionStarting Point. Pin
UniBond13-Oct-05 2:02
UniBond13-Oct-05 2:02 
AnswerRe: Starting Point. Pin
Tom John13-Oct-05 3:32
Tom John13-Oct-05 3:32 
QuestionComma Separated Numbers Pin
Greeky13-Oct-05 1:38
Greeky13-Oct-05 1:38 
AnswerRe: Comma Separated Numbers Pin
Tom John13-Oct-05 3:24
Tom John13-Oct-05 3:24 
QuestionCan subroutine in VB DLL accept array variable argument??? Pin
Anonymous13-Oct-05 0:58
Anonymous13-Oct-05 0:58 
Questiontrap-inputbox Pin
himanshu_softin12-Oct-05 23:44
himanshu_softin12-Oct-05 23:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.