我怎么知道哪些选项卡中,从/移动到一个WinForms标签控件? [英] How do I tell which tab you are moving from/to in a WinForms tab control?

查看:183
本文介绍了我怎么知道哪些选项卡中,从/移动到一个WinForms标签控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要确定哪个选项卡,用户是从哪里来的,和去,当他们切换标签,并可以取消开关。我曾尝试取消选择,取消选择,选择,选择的事件,所有这些都显示了e.TabPageIndex是相同sender.SelectedIndex。

I need to determine which tab the user is coming from, and going to, when they switch tabs, and possibly cancel the switch. I have tried the Deselecting, Deselected, Selecting, Selected events, and all of them show the e.TabPageIndex to be the same as the sender.SelectedIndex.

有一个事件,或财产,那我可以使用,这样我能确定这两面,或做我必须从一个事件的缓存,并采用了新的事件该值砍东西在一起。

Is there an event, or property, that I can use so that I can determine both sides of this, or do I have to hack something together with caching it from one event and using that value in the new event.

我试图避免处理取消选择/取消选择的事件,并缓存在选择时要使用的值。我已经知道我可以做到这一点,所以我问,如果有一个更清洁的方式,没有这样做。

I am trying to avoid handling the Deselecting/Deselected events and caching the value to use in the Selecting event. I already know I can do this, so I am asking if there is a cleaner way, without doing this.

我曾在C#和VB,具有相同的结果(这并不足为奇)。

I have tried in both C# and VB, with the same results (no surprise).

感谢。

推荐答案

它看起来并不像任何一个事件的说法将携带双方的previous和当前选项卡中的细节,所以你需要处理几个事件跟踪。

It doesn't look like any one event argument will carry the details of both the previous and current tabs, so you'll need to handle a couple of events to keep track.

在最低限度,你需要使用取消选中事件存储一个参考previously选择的选项卡。您可以随时查询的TabControl其当前选项卡。舒展远一点,你也可以处理事件跟踪当前选项卡。

At a minimum, you'd need to use the Deselected event to store a reference to the previously-selected tab. You can always query the TabControl for its current tab. To stretch a little further, you can also handle the Selected event to track the current tab.

Option Strict On
Option Explicit On

Public Class Form1

    Private PreviousTab As TabPage
    Private CurrentTab As TabPage

    Private Sub TabControl1_Deselected(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlEventArgs) Handles TabControl1.Deselected
        PreviousTab = e.TabPage
        Debug.WriteLine("Deselected: " + e.TabPage.Name)
    End Sub

    Private Sub TabControl1_Selected(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlEventArgs) Handles TabControl1.Selected
        CurrentTab = e.TabPage
        Debug.WriteLine("Selected: " + e.TabPage.Name)
    End Sub

    Private Sub TabControl1_Selecting(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlCancelEventArgs) Handles TabControl1.Selecting
        If CurrentTab Is Nothing Then Return
        Debug.WriteLine(String.Format("Proposed change from {0} to {1}", CurrentTab.Name, e.TabPage.Name))
    End Sub

End Class

这篇关于我怎么知道哪些选项卡中,从/移动到一个WinForms标签控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆