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. Other Discussions
  3. Clever Code
  4. Super-lightweight WinForms TabControl

Super-lightweight WinForms TabControl

Scheduled Pinned Locked Moved Clever Code
csharpwinforms
4 Posts 3 Posters 16 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.
  • L Offline
    L Offline
    Lutoslaw
    wrote on last edited by
    #1

    This is a tab control without tabs for those who don't need them (eg when the SelectedIndex property is set programmaticaly).

    public class NoTabControl : ContainerControl
    {
    private int selectedIndex = -1;

    public int SelectedIndex
    {
    	get { return selectedIndex; }
    	set
    	{
    		if (value < 0 || value >= Controls.Count)
    			throw new ArgumentOutOfRangeException();
    		if (selectedIndex != -1)
    		        Controls\[selectedIndex\].Visible = false;
    		selectedIndex = value;
    		Controls\[selectedIndex\].Visible = true;
    	}
    }
    protected override void OnControlAdded(ControlEventArgs e)
    {
    	base.OnControlAdded(e);
    	e.Control.Visible = false;
    }
    

    }

    Not sure if it is wicked enought for this forum but can be useful anyway.

    Greetings - Jacek

    L W 2 Replies Last reply
    0
    • L Lutoslaw

      This is a tab control without tabs for those who don't need them (eg when the SelectedIndex property is set programmaticaly).

      public class NoTabControl : ContainerControl
      {
      private int selectedIndex = -1;

      public int SelectedIndex
      {
      	get { return selectedIndex; }
      	set
      	{
      		if (value < 0 || value >= Controls.Count)
      			throw new ArgumentOutOfRangeException();
      		if (selectedIndex != -1)
      		        Controls\[selectedIndex\].Visible = false;
      		selectedIndex = value;
      		Controls\[selectedIndex\].Visible = true;
      	}
      }
      protected override void OnControlAdded(ControlEventArgs e)
      {
      	base.OnControlAdded(e);
      	e.Control.Visible = false;
      }
      

      }

      Not sure if it is wicked enought for this forum but can be useful anyway.

      Greetings - Jacek

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Huh? Why would you use a control for something you dont need?

      xacc.ide
      IronScheme - 1.0 beta 3 - out now!
      ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))

      L 1 Reply Last reply
      0
      • L leppie

        Huh? Why would you use a control for something you dont need?

        xacc.ide
        IronScheme - 1.0 beta 3 - out now!
        ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))

        L Offline
        L Offline
        Lutoslaw
        wrote on last edited by
        #3

        leppie wrote:

        Why would you use a control for something you dont need?

        I think you misunterstood me. By "tab" I meant a clickable area with a title which is used to switch between panels. Panels in the NoTabControl can be switched programmaticaly, but no actual tabs are rendered.

        Greetings - Jacek

        1 Reply Last reply
        0
        • L Lutoslaw

          This is a tab control without tabs for those who don't need them (eg when the SelectedIndex property is set programmaticaly).

          public class NoTabControl : ContainerControl
          {
          private int selectedIndex = -1;

          public int SelectedIndex
          {
          	get { return selectedIndex; }
          	set
          	{
          		if (value < 0 || value >= Controls.Count)
          			throw new ArgumentOutOfRangeException();
          		if (selectedIndex != -1)
          		        Controls\[selectedIndex\].Visible = false;
          		selectedIndex = value;
          		Controls\[selectedIndex\].Visible = true;
          	}
          }
          protected override void OnControlAdded(ControlEventArgs e)
          {
          	base.OnControlAdded(e);
          	e.Control.Visible = false;
          }
          

          }

          Not sure if it is wicked enought for this forum but can be useful anyway.

          Greetings - Jacek

          W Offline
          W Offline
          Win8128
          wrote on last edited by
          #4

          Pretty cool, thanks for showing it.

          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