我希望能够在单击按钮时显示菜单,而在再次单击按钮时隐藏相同的菜单。我不确定如何执行此操作,任何帮助都将非常有用!我的点击功能如下。
Private Sub btnMeasure_Click(sender As Object, e As RoutedEventArgs) Handles btnMeasure.Click
Try
If Constants.MapAction.SetMapAction(mapActionEnum.Measure) Then
Dim measureForm As New frmMeasure(mpMapView)
measureForm.Show()
End If
Catch ex As Exception
Constants.WriteToErrorLog(System.Reflection.MethodBase.GetCurrentMethod.DeclaringType.Name,
System.Reflection.MethodInfo.GetCurrentMethod.Name,
ex)
End Try
End Sub
答案 0 :(得分:0)
在“类”范围内声明/设置表单,而不是在此子目录中:
Public Class YourClass
Dim measureForm As New frmMeasure(mpMapView)
和您的按钮点击事件:
Private Sub btnMeasure_Click(sender As Object, e As EventArgs) Handles btnMeasure.Click
If measureForm.Visible Then
measureForm.Hide()
Else
measureForm.Show()
End If
End Sub
答案 1 :(得分:0)
您需要检查关闭表单时的边缘情况,并且需要创建一个新实例。我认为您正在使用WPF,但这是WinForms中的样子:
Public Class Form1
Private measureForm As frmMeasure = Nothing
Private Sub btnMeasure_Click(sender As Object, e As RoutedEventArgs) Handles btnMeasure.Click
Try
If Constants.MapAction.SetMapAction(mapActionEnum.Measure) Then
If IsNothing(measureForm) OrElse measureForm.IsDisposed Then
measureForm = New frmMeasure(mpMapView)
measureForm.Show()
ElseIf Not measureForm.Visible Then
measureForm.Show()
Else
measureForm.Hide()
End If
End If
Catch ex As Exception
'Constants.WriteToErrorLog(System.Reflection.MethodBase.GetCurrentMethod.DeclaringType.Name,
' System.Reflection.MethodInfo.GetCurrentMethod.Name,
' ex)
End Try
End Sub
End Class