【问题标题】:Set selected tab without selectedIndexChanged event firing设置选定的选项卡而不触发 selectedIndexChanged 事件
【发布时间】:2012-04-26 11:01:54
【问题描述】:

有没有办法在不触发 selectedIndexchanged 事件的情况下设置 tabControl 的选定选项卡?

例如选择 myTabPage2 时会触发此事件,因为 myTabPage1 是默认值:

Private Sub setupTabControl
    If blnHasAccount=true then
       MyTabControl.selectedTab=myTabPage1
    else
       MyTabControl.selectedTab=myTabPage2
    End if
End sub

Private Sub MyTabControl_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyTabControl.SelectedIndexChanged
    'Do stuff (but only when user has actually changed the tab themselves)
End Sub

【问题讨论】:

    标签: vb.net visual-studio-2008 tabcontrol


    【解决方案1】:

    当您设置新标签页时,您可以删除事件处理程序

    Try
        RemoveHandler MyTabControl.SelectedIndexChanged, AddressOf Me.MyTabControl_SelectedIndexChanged
        .. do your works to change page here
        .. and then reconnect
    Finally
        AddHandler MyTabControl.SelectedIndexChanged, AddressOf Me.MyTabControl_SelectedIndexChanged
    End Try
    

    将所有内容包含在 Try Final 中以从异常中正确恢复非常重要

    【讨论】:

      【解决方案2】:

      可以在进行更改时伪造并检查 ComboBox.Enabled 作为在 SelectedIndexChanged 事件中使用的标志,然后在完成后设置回 true。但是,此类事件仍会触发(应该吗?),但至少您可以确保全局“组合框”变量的状态。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多