public class FTabControl : System.Windows.Forms.TabControl{   
private System.ComponentModel.Container components = null;   
private static Color BackColor=Color.FromArgb(227,237,251);   
private static Color ButtonColor;   
private static Color ButtonHighlightColor;   
private static Color BorderColor=Color.Black;   
public bool UserChangeTab=true;   
  
public FTabControl(){   
InitializeComponent();   
SetDafaultStyle();   
SetStyle(ControlStyles.UserPaint,true);   
}   
 
#region Component Designer generated code   
private void InitializeComponent(){   
components = new System.ComponentModel.Container();   
}   
#endregion   
  
public void SetDafaultStyle(){   
Appearance = System.Windows.Forms.TabAppearance.FlatButtons;   
ButtonColor = Color.FromArgb(184,210,250);   
ButtonHighlightColor = Color.FromArgb(144,187,252);   
}   
  
protected override void OnPaint(PaintEventArgs e){   
e.Graphics.FillRectangle(new SolidBrush(BackColor),e.ClipRectangle);   
for (int i=0;i<this.TabCount;i++){   
DrawItem(e.Graphics,i);   
}   
}   
  
protected void DrawItem(Graphics g,int index){   
Rectangle r = GetTabRect(index);   
r.Inflate(-2,-2);   
if (SelectedIndex==index)   
g.FillRectangle(new SolidBrush(ButtonHighlightColor),r);   
else   
g.FillRectangle(new SolidBrush(ButtonColor),r);   
g.DrawRectangle(new Pen(new SolidBrush(BorderColor)),r);   
r.Inflate(-3,-3);   
g.DrawString(TabPages[index].Text,Font,new SolidBrush(BorderColor),r);   
}   
  
protected override void WndProc(ref System.Windows.Forms.Message m){   
if (m.Msg == 513 && !this.UserChangeTab ){   
return; //trap WM_LBUTTONDOWN   
}   
else{   
base.WndProc(ref m);   
}   
}   
  
protected override void OnKeyDown(KeyEventArgs e){   
if(e.Control==true && e.KeyCode==System.Windows.Forms.Keys.Tab && !this.UserChangeTab){   
return; //trap CTRL+TAB and CTRL+SHIFT+TAB   
}   
else{   
base.OnKeyDown(e);   
}   
}   
}   最近在学怎么使TabContro控件的子页隐藏起来!找了这些代码。可不是很理解是什么意思?请各位高手帮我解释下 最好能详细点的  还有重点 我不知道这些代码怎么用呀? 要用再哪呢?? 小弟是个菜鸟。也许这样问会让大家笑话 不过不懂就要问所以还是要麻烦你们了

解决方案 »

  1.   

    TabControl1.Region=New Region(TabPage1.Left,TabControl1.Height-TabPage1.Height,TabPage1.Width,TabPage1.Height)
      

  2.   

      
    SetStyle(ControlStyles.UserPaint,true);   
    UserPaint 如果为 true,控件将自行绘制,而不是通过操作系统来绘制。如果为 false,将不会引发 Paint 事件。
    参考 
      

  3.   

    使用很简单,你创建一个类,把代码拷贝进去,编译一下,就能看到工具箱上多出一个FTabControl控件,拖到Form上就能用,关键是它不能实现隐藏!
      

  4.   

    SetStyle(ControlStyles.UserPaint,true);   
    UserPaint 如果为 true,控件将自行绘制,而不是通过操作系统来绘制。如果为 false,将不会引发 Paint 事件。
    试试!~