TabControl.cs :  » Persistence-Frameworks » Data-Holder » DBWebControls » WebControls » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Persistence Frameworks » Data Holder 
Data Holder » DBWebControls » WebControls » TabControl.cs
using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.ComponentModel.Design;
using System.Drawing.Design;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Text;

namespace DBWebControls.WebControls{
  /// <summary>
  /// Summary description for TabControl.
  /// </summary>
  [Designer(typeof(TabControlDesigner)),
  ToolboxData("<{0}:TabControl runat=\"server\"></{0}:TabControl>"),
  ParseChildren(true, "TabPages"), //needed by the page parser
  PersistChildren(false) // Needed by the designer
  ]
  public class TabControl:Control, INamingContainer
  {
    private TabPageCollection m_TabPages = new TabPageCollection();
    private int l_SelectedPageIndex = -1;
    private string m_BackGroundImageUrl = string.Empty;
    private string m_TabBackSelectedImageUrl=string.Empty;
    private string m_TabBackUnSelectedImageUrl=string.Empty;
    private const string IDPrefix = "TabPage__";
    private const string SelectedIndexViewSateKey = "TabSelectedIndex";
    //private System.ComponentModel.Container components = null;
    public TabControl()
    {
      
      //
      // TODO: Add constructor logic here
      //
    }

    #region Properties
    [Bindable(false),
    Browsable(false)]
    public int SelectedPageIndex
    {
      get      
      {        
        if(l_SelectedPageIndex < 0 || l_SelectedPageIndex >= TabPages.Count)
        {
          object tmp = this.ViewState[SelectedIndexViewSateKey];
          if(tmp != null)
            l_SelectedPageIndex = (int)tmp;
          else
            l_SelectedPageIndex = 0;
        }
        return l_SelectedPageIndex;
      }
    }


    [
    Bindable(true),
    Browsable(true),
    Category("Window"),
    Editor(typeof(TabPageCollectionEditor), typeof(UITypeEditor)),
    DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
    PersistenceMode(PersistenceMode.InnerDefaultProperty),
    Description("Collection of Property(string Key, string Value) objects sent to Modal Window.")
    ]
    public TabPageCollection TabPages
    {
      get{return m_TabPages;}
    }

    [Category("Windows"),
    Description("BackGround image"),
    Bindable(true),
    Browsable(true),
    Localizable(false),
    DefaultValue(""),
    Editor(typeof( System.Web.UI.Design.UrlEditor), typeof(UITypeEditor))]
    public string BackGroundImageUrl
    {
      get{return m_BackGroundImageUrl;}
      set{m_BackGroundImageUrl = value;}
    }

    [Category("Windows"),
    Description("image shown when the tab page is selected"),
    Bindable(true),
    Browsable(true),
    Localizable(false),
    DefaultValue(""),
    Editor(typeof( System.Web.UI.Design.UrlEditor), typeof(UITypeEditor))]
    public string TabBackSelectedImageUrl
    {
      get{return m_TabBackSelectedImageUrl;}
      set{m_TabBackSelectedImageUrl = value;}
    }

    [Category("Windows"),
    Description("image shown when the tab page is not selected"),
    Bindable(true),
    Browsable(true),
    Localizable(false),
    Editor(typeof(System.Web.UI.Design.UrlEditor), typeof(UITypeEditor))]
    public string TabBackUnSelectedImageUrl
    {
      get{return m_TabBackUnSelectedImageUrl;}
      set{m_TabBackUnSelectedImageUrl = value;}
    }
    #endregion

    protected override void OnPreRender(EventArgs e)
    {
      base.OnPreRender (e);
      if(TabPages.Count <= 0)
        return;

      for(int i = 0; i < TabPages.Count; i++)
      {
        Control ctrl = this.Parent.FindControl(TabPages[i].TabPageControlID);
        if(ctrl != null)
          ctrl.Visible = (i == SelectedPageIndex);
      }
      Control tmp = this.FindControl(IDPrefix+TabPages[SelectedPageIndex].TabPageName);
      ((HtmlControl)tmp.Parent).Attributes["class"] = "selected";
      this.ViewState.Add(SelectedIndexViewSateKey, SelectedPageIndex);
    }


    protected override void CreateChildControls()
    {
      base.CreateChildControls ();
      HtmlGenericControl div = new HtmlGenericControl("div");
      div.Attributes["class"] = "shadetabs";
      HtmlGenericControl ul = new HtmlGenericControl("ul");
      ul.EnableViewState = false;
//      HtmlTable htmltable = new HtmlTable();
//      htmltable.EnableViewState = false;
//      if(m_BackGroundImageUrl.Length > 0)
//        htmltable.Attributes["background"] = m_BackGroundImageUrl;
//      htmltable.Rows.Add(new HtmlTableRow());
//      htmltable.Rows[0].EnableViewState = false;
      
      foreach(TabPage tp in m_TabPages)
      {
//        HtmlGenericControl gc = new HtmlGenericControl("div");
//        HtmlTableCell tcell = new HtmlTableCell();

        HtmlGenericControl li = new HtmlGenericControl("li");


        LinkButton lb = new LinkButton();
        //lb.Style["BACKGROUND-IMAGE"] = "url("+m_TabBackSelectedImageUrl+")";
        //lb.Style["BACKGROUND-REPEAT"] = "repeat-x";
        lb.Text = tp.TabPageText;
        lb.ID = IDPrefix+tp.TabPageName;
        lb.Click +=new EventHandler(lb_Click);
        lb.EnableViewState = false;

        li.Controls.Add(lb);
        li.EnableViewState = false;
        
//        tcell.EnableViewState = false;
//        tcell.Controls.Add(lb);
        ul.Controls.Add(li);
      }
      div.Controls.Add(ul);
      this.Controls.Add(div);
    }

    private void lb_Click(object sender, EventArgs e)
    {
      int tmpi = TabPages.GetTabPageIndexByName(((Control)sender).ID.Substring(IDPrefix.Length));
      if(tmpi >= 0)
        l_SelectedPageIndex = tmpi;
    }
  }

  /// <summary>
  /// Class for displaying WebModalAnchor in designer
  /// </summary>
  internal class TabControlDesigner : System.Web.UI.Design.ControlDesigner
  {
    #region Overriden methods

    /// <summary>
    /// Returns HTML code to show in designer
    /// </summary>
    public override string GetDesignTimeHtml()
    {
      StringBuilder sb = new StringBuilder(300);
      sb.Append(@"<div style=""padding:1px; background-color: #333333;color:#FFFFFF;font:12px Verdana  " +
        " border-style:outset; border-width:1px; font: 75% 'Microsoft Sans Serif';\">&nbsp;<span style=\"color:#FAB301\">TABCONTROL</span> "+((Control)Component).ID +
        "&nbsp;<br/>Ver.&nbsp;"+ this.GetType().Assembly.GetName().Version +
        "</div>");
      return sb.ToString();      
    }
    
    #endregion
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.