Link to home
Start Free TrialLog in
Avatar of ArunVashist
ArunVashistFlag for India

asked on

Hi Apncealbuerne,

I am trying to do same for a leave event of tab page, but there is no such e.Cancel method available.
Please guide me, actually i am trying to prompt a user if he want to navigate away from current tab page or not if user selects No then Leave event must get cancel and user must remains on the same tab page.

Please guide.
Thanks in Advance.
SOLUTION
Avatar of JackOfPH
JackOfPH
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Selecting event will trigger before the tab was moved so you can use it.
Use the Selecting event of the tab instead of leave event.
I hope you  get the idea...

Jack

The code is something like the one posted below...


Private Sub TabControl1_Selecting(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlCancelEventArgs) Handles TabControl1.Selecting
        If MessageBox.Show("Do you want to move to other page?", "Testing", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
            e.Cancel = True
        End If
    End Sub

Open in new window

Avatar of ArunVashist

ASKER

Hi JackOfPH,

the suggested "Selecting" event works fine, but the Issue is with leave event only, actually user can also leave the Tab Page by selecting some other option from Menu in that case current Tab control is hidden and requested Tab control appears. now I am managing the "Visiblechanged" event to get the current SelectedIndex of TabControl and accordingly fill the controls.

Now what i exactly need is a Prompt when user switch to other Tab page in same Tab control or  when user switch to other Tab Control.

Thanks in advance,
Arun Vashist
okey, why don't you put the checking everytime you are prompted to created the tab?


Private Sub ViewTabpage(ByVal TabName As String, ByVal myControls As BaseClass.BaseModule)
       
         If MessageBox.Show("Do you want to move to other page?", "Testing", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                   
        Dim objTabpage As New TabPage

        objTabpage.Name = TabName
        objTabpage.Text = TabName
     
        TabControl1.Controls.Add(objTabpage)
else
   'Do staff if user decide to stay in the tab...
       End IF
End Sub
Hey JackOfPH,

I am not adding and removing tabs programmatically, actually all tab controls and respective tab pages are pre-designed, we just hide and show the tab controls according to option selected by user from menu.

So we need two prompts one when tab control leaves focus or hide and second when user switches between tap pages.

thanks,
Can you show me on how you hide the tab?
A sample code may help you explain better my point...
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial