PvpMan22 PvpMan22 - 1 year ago 86
C# Question

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 clicks 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.

jfs jfs
Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download