1

如果我的问题标题有点含糊,我深表歉意。我有下面调用表单的过程。超链接调用相同的表单,通过一个子。一切都很好,问题是如果我单击一个链接,然后单击另一个,表单会打开两次,这是应该发生的,因为我将表单实例化为 New。

我想要做的是只打开相同的表单,这样如果用户点击链接,那么只有一个表单打开而不是几个。

    Private Sub dsbPositionBoard_FollowHyperlink(Target As Microsoft.Office.Interop.Excel.Hyperlink) Handles Me.FollowHyperlink

    'This procedure runs when any of the hyperlinked cells in the position dashboard are clicked
    'The hyperlinks open the frmDefinition on the assigned defintion. The procedure calls
    'the function. 

    'The hyperlinked cells are assigned under the ThisWorkbook/Open event.

    Dim definitionForm As New frmDefinitions

    Select Case Target.TextToDisplay

        Case "Exempt"
            definitionForm.tmr_out.Enabled = True
            sheetView.exemptDefinition()

        Case "Employee Pay Distribution for Ranges", "Low Third", "Upper Third"
            definitionForm.tmr_out.Enabled = True
            sheetView.lowerThirdDefinition()

        Case "Market Percentiles"
            definitionForm.tmr_out.Enabled = True
            sheetView.marketPercentileDefinition()

        Case "Min", "Mid", "Max", "Salary Range to Mkt"
            definitionForm.tmr_out.Enabled = True
            sheetView.payGradeWidthDefintion()

        Case "Total Cash Compensation Data"
            definitionForm.tmr_out.Enabled = True
            sheetView.totalCashCompDefition()

        Case "Compa-Ratio"
            definitionForm.tmr_out.Enabled = True
            sheetView.compaRatioDefinition()

    End Select

End Sub
4

1 回答 1

1

您有两个选择:frmDefinitions全局定义给定变量并在需要时关闭/打开它;或将其作为参数传递给函数。

我猜您的情况(通过假设典型条件)的最佳选择是全局定义。下面我包含一个基于标准的小代码Form,你不应该发现任何问题来适应你的特定frmDefinitions类:

Public Class Form1
    Dim definitionForm As New Form

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

        definitionForm.Close()

        definitionForm = New Form
        definitionForm.Show()

    End Sub
End Class

如您所见,当您单击时Button1,表单definitionForm会反复使用(之前的实例关闭,新的实例创建和打开)。

于 2013-08-06T17:58:30.257 回答