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控件的子页隐藏起来!找了这些代码。可不是很理解是什么意思?请各位高手帮我解释下 最好能详细点的 还有重点 我不知道这些代码怎么用呀? 要用再哪呢?? 小弟是个菜鸟。也许这样问会让大家笑话 不过不懂就要问所以还是要麻烦你们了
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控件的子页隐藏起来!找了这些代码。可不是很理解是什么意思?请各位高手帮我解释下 最好能详细点的 还有重点 我不知道这些代码怎么用呀? 要用再哪呢?? 小弟是个菜鸟。也许这样问会让大家笑话 不过不懂就要问所以还是要麻烦你们了
解决方案 »
- 关于限制登录用户对一篇文章评分一次的功能实现
- 怎么操作主窗口的statusStrip?
- 兄弟们帮帮小弟
- c#水晶报表部署到客户机后,纸张格式总是默认为A4
- C#操作EXCEL 引入组件库后编译报错
- 为什么DLL 没法调用WebService,打不到类
- 关于在WebForm中的Table的背景图片的问题
- ---------------------请问这个C#的语句怎样改成VB的---------------------???
- 有那位高人知道怎么将流中二进制的rtf格式解码。C#的代码,我用在ASP.Net中
- 关于SQL注入
- 求一个匹配算法,c#写的。
- 我这个要实现对数据库中内容的修改且显示在Datagrid中,请大家帮帮忙看一下 啊
SetStyle(ControlStyles.UserPaint,true);
UserPaint 如果为 true,控件将自行绘制,而不是通过操作系统来绘制。如果为 false,将不会引发 Paint 事件。
参考
UserPaint 如果为 true,控件将自行绘制,而不是通过操作系统来绘制。如果为 false,将不会引发 Paint 事件。
试试!~