如何检测标签页的TabControl的前SelectedIndexChanged事件的变化? [英] How do I detect a change of tab page in TabControl prior to SelectedIndexChanged event?
问题描述
我目前确定页的TabControl的是通过的SelectedIndexChanged
事件点击。
I currently determine what page of a tabcontrol was clicked on via the SelectedIndexChanged
event.
我想检测的在的所选择的指数实际上改变,是为了进行验证。例如,用户点击一个标签页比他们观看另外一个。一个对话是psented $ P $如果表单数据未保存,并询问它是否可以继续。如果用户单击否,用户应保持目前的标签。
I would like to detect before the selected index actually changes, for validation purposes. For example, a user clicks a tab page other than the one they are viewing. A dialog is presented if form data is unsaved and asks if it's ok to proceed. If the user clicks no, the user should remain on the current tab.
目前我已经记住了previous标签页和答案后切换回它没有。
Currently I have to remember the previous tab page and switch back to it after an answer of 'no.'
我考虑的MouseDown(与配套计算逻辑),但我怀疑这是最好的办法。
I considered MouseDown (and the assorted calculation logic), but I doubt that's the best way.
推荐答案
添加这样的事件到TabControl时的Form_Load。
Add such an event to the tabControl when form_load.
tabControl1.Selecting += new TabControlCancelEventHandler(tabControl1_Selecting);
void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
{
TabPage current = (sender as TabControl).SelectedTab;
//validate the current page, to cancel the select use:
e.Cancel = true;
}
这篇关于如何检测标签页的TabControl的前SelectedIndexChanged事件的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!