开发者

Windows Form Tabs switching

I have three tabs in a Windows Forms tab control. Currently in Tab1 I have a button that saves the information in a textbox and automatically changes the tabcontrol.SelectedIndex to Tab2. Tab2 then uses the information saved from tab1's textbox.

I want a messagebox to popup whenever the user changes the textbox in tab1, but then manually clic开发者_如何学运维ks tab2 or tab3 without hitting the button to save the information.

So in summary, I have it so clicking a button on tab1 automatically sends it to tab2. I want a messagebox to pop up if the button on tab1 is not pressed when the information was changed and the user manually changed the tab.


I think a wizard-like design for your application is more appropriate. Tabs are not supposed to work like that from a user's perspective.

But a workaround for your current situation is:

  • declare a variable, for example dirty
  • set this variable whenever any control in tab1 has been edited
  • clear the variable if the button in tab1 is clicked
  • check this if tab2 or tab3 is selected


You can use the Deselecting event on the TabControl to be informed when the selected tab is changing. If the tab that is being deselected is the tab with the button on it and the information is not saved, you can display the message box.

Also, depending on what your program does, it may make more sense to go ahead and save the information when the tab changes without even bothering the user.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜