Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to cancel a tab page change

how to cancel a tab page change

Scheduled Pinned Locked Moved C#
csharptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NikoTanghe
    wrote on last edited by
    #1

    How to cancel a tabcontrol selectedindex event? I can't find a proper event to do this. in 2.0 framework, some events were added: Deselected : Occurs when a tab is deselected. Deselecting : Occurs before a tab is deselected, enabling a handler to cancel the tab change. but how is it possible in .net < 2.0 :confused: thanks in advance, Niko

    C 1 Reply Last reply
    0
    • N NikoTanghe

      How to cancel a tabcontrol selectedindex event? I can't find a proper event to do this. in 2.0 framework, some events were added: Deselected : Occurs when a tab is deselected. Deselecting : Occurs before a tab is deselected, enabling a handler to cancel the tab change. but how is it possible in .net < 2.0 :confused: thanks in advance, Niko

      C Offline
      C Offline
      Curtis Schlak
      wrote on last edited by
      #2

      You could hack the change by creating your own derived class from TabControl and just monitor the SelectedIndexChanged event. The following code will prevent a user from selecting the third tab in the MyTabControl class.

      using System;
      using System.Windows.Forms;

      namespace WindowsApplication1
      {
      public class MyTabControl : TabControl
      {
      private int lastSelectedIndex = 0;
      public MyTabControl() : base()
      {
      lastSelectedIndex = this.SelectedIndex;
      this.SelectedIndexChanged +=
      new EventHandler( SelectedIndexChanged );
      }

      private void SelectedIndexChanged( object sender, EventArgs e )
      {
        // Prevent someone from choosing TabPage number 3.
        if( this.SelectedIndex == 2 )
        {
          this.SelectedIndex = lastSelectedIndex;
        }
        else
        {
          lastSelectedIndex = this.SelectedIndex;
        }
      }
      

      }
      }

      "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups