0

我已经尝试将我的输入控件放在组框和面板框中,并将用户选择的组/面板框的 .Visible 属性更改为 True,并将所有其他属性更改为 false。

我是不是在找错树并认为这个 UI 设计是错误的?这是我到目前为止编写的代码:

Public Class frmMainMenu

Dim blnIncident As Boolean = False
Dim blnPatient As Boolean = False
Dim blnAssessments As Boolean = False
Dim blnInterventions As Boolean = False
Dim blnNarrative As Boolean = False

Private Sub PanelFocus()

    If blnIncident = True Then

        pnlIncidentInfo.Visible = True
        pnlPatientInformation.Visible = False
        pnlAssessments.Visible = False
        pnlInterventions.Visible = False
        pnlNarrative.Visible = False

    ElseIf blnPatient = True Then

        pnlPatientInformation.Visible = True
        pnlIncidentInfo.Visible = False
        pnlAssessments.Visible = False
        pnlInterventions.Visible = False
        pnlNarrative.Visible = False

    ElseIf blnAssessments = True Then

        pnlAssessments.Visible = True
        pnlIncidentInfo.Visible = False
        pnlPatientInformation.Visible = False
        pnlInterventions.Visible = False
        pnlNarrative.Visible = False

    ElseIf blnInterventions = True Then

        pnlInterventions.Visible = True
        pnlIncidentInfo.Visible = False
        pnlAssessments.Visible = False
        pnlPatientInformation.Visible = False
        pnlNarrative.Visible = False

    ElseIf blnNarrative = True Then

        pnlNarrative.Visible = True
        pnlIncidentInfo.Visible = False
        pnlPatientInformation.Visible = False
        pnlAssessments.Visible = False
        pnlInterventions.Visible = False

    End If

End Sub

Private Sub btnIncident_Click(sender As System.Object, e As System.EventArgs) Handles btnIncident.Click

    blnIncident = True
    PanelFocus()

End Sub


Private Sub btnPatientInfo_Click(sender As System.Object, e As System.EventArgs) Handles btnPatientInfo.Click

    blnPatient = True
    PanelFocus()

End Sub

Private Sub btnVitals_Click(sender As System.Object, e As System.EventArgs) Handles btnVitals.Click
    blnAssessments = True
    PanelFocus()

End Sub

Private Sub btnInterventions_Click(sender As System.Object, e As System.EventArgs) Handles btnInterventions.Click
    blnInterventions = True
    PanelFocus()

End Sub

Private Sub btnNarrative_Click(sender As System.Object, e As System.EventArgs) Handles btnNarrative.Click
    blnNarrative = True
    PanelFocus()

End Sub

End Class

谢谢,

斯科特

[编辑]

我想我找到了问题所在。我无意中将一些面板框控件放在一起,从而与父面板建立了子关系。它们不会显示,因为...父控件的可见属性设置为 false。在 sub 调用之后,我还忘记将用户选择的布尔变量设置回 false。

感谢那些花时间阅读我的问题的人。如果您有更好的方法来完成我想做的事情,请随时分享或联系我。

斯科特

4

2 回答 2

1

Since all your code is doing, is making one panel Visible while making all the others invisible. One way to make it easier to understand your code later and make it quite a bit leaner, is to set the buttons' click events to be handled by the same handler. Then in the handler, iterate through the panels making them all invisible except for the one matching the clicked button, make it Visible

Something like this:

For Each btn as Button in Me.Controls.OfType(Of Button)
    AddHandler btn.Click, AddressOf Button_Click
Next

Private Sub Button_Click(sender As Object, e As EventArgs)
    Dim ClickedButton as Button = DirectCast(sender, Button)
    For Each p as Panel in Me.Controls.OfType(Of Panel)
        If p.Name.Contains(ClickedButton.Name.Substring(3)) Then
            p.Visible = True
        Else
            p.Visible =False
        End If
End Sub

One other change you'll have to make, for this code to work, is change the name of btnVitals to btnAssessments.

于 2013-06-02T05:13:01.130 回答
1

您所做的可能有效,但很难维护。为每个场景创建一个用户控件会是更好的代码。

考虑每个场景的共同属性并定义一个接口。然后让每个用户控件实现接口。

一开始它的额外工作 - 但从长远来看会得到回报。

于 2013-06-01T22:29:26.793 回答