C# winform中 tabcontrol 的美化问题,急救

kenriy 2010-11-27 10:53:30


像这样的效果怎么做出来呢?
我不知道这个边框和选项卡怎么弄协调,我的效果成这样:
http://www.aotongda.com/tabControl1.jpg
选项卡和边框不会弄,
请高手帮忙,急救!!!!!
...全文
1811 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangxhBest 2011-12-06
  • 打赏
  • 举报
回复
悲惨 我在写程序的时候也用到了皮肤 我也遇到了一样的问题诶 如果你的问题 解决了 跟我说一下 嘛 谢谢

我qq 583782308
wangxhBest 2011-12-06
  • 打赏
  • 举报
回复
悲催 你的问题解决了没有 我也遇到了一样的问题诶
思嘉 2011-09-20
  • 打赏
  • 举报
回复
u p
kenriy 2010-12-02
  • 打赏
  • 举报
回复
有没有更简单的方法美化它呢?
amanda04 2010-11-30
  • 打赏
  • 举报
回复
public Formtest()
{
tabControl1 = new TabControl();
TabPage tabPage1 = new TabPage();
tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;

tabControl1.Controls.Add(tabPage1);
tabControl1.Location = new Point(25, 25);
tabControl1.Size = new Size(250, 250);

tabPage1.TabIndex = 0;

myTabRect = tabControl1.GetTabRect(0);

ClientSize = new Size(300, 300);
Controls.Add(tabControl1);

tabControl1.DrawItem += new DrawItemEventHandler(OnDrawItem);
}

private void OnDrawItem(object sender, DrawItemEventArgs e)
{
Graphics g = e.Graphics;
Pen p = new Pen(Color.Blue);
g.DrawImage(SheetsPC.Properties.Resources.TESTIMG, myTabRect);
}
kenriy 2010-11-30
  • 打赏
  • 举报
回复
考虑用第三方控件,自己做吃力不讨好!
fs_rong123 2010-11-28
  • 打赏
  • 举报
回复
路过!!!!!!!!!!
yishui6666 2010-11-28
  • 打赏
  • 举报
回复
考虑用第三方控件,自己做吃力不讨好!
jiangjun110120 2010-11-28
  • 打赏
  • 举报
回复
常用的控件都很好的设样式
jiangjun110120 2010-11-28
  • 打赏
  • 举报
回复
用dotNetBar自定义控件嘛,
东莞寻香苑 2010-11-27
  • 打赏
  • 举报
回复
用控件IrisSkin2.dll
就会自动那样了
CraxyMouse 2010-11-27
  • 打赏
  • 举报
回复
效果图


CraxyMouse 2010-11-27
  • 打赏
  • 举报
回复
老早之前写的一个
你看看主要看看思路就可以了

[ToolboxBitmap(typeof(TabControl))]
public partial class Tab : TabControl
{
static Image img;
public Tab():base()
{
//this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.ItemSize = new Size(0,15);
this.ResizeRedraw = true;
img = ControlCommon.GetImageFromResource("eTab.png");//GetResBitmap("Tangxu.Controls.Images.eTab.png");
}
~Tab()
{
if (img != null)
{
img.Dispose();
}
}

protected override void OnPaintBackground(PaintEventArgs pevent)
{
this.InvokePaintBackground(this.Parent, pevent);
this.InvokePaint(this.Parent, pevent);
}

protected override void OnPaint(PaintEventArgs e)
{

this.PaintAllTheTabs(e);
this.PaintTheTabPageBorder(e);
}

private void PaintAllTheTabs(System.Windows.Forms.PaintEventArgs e)
{
if (this.TabCount > 0)
{
for (int index = 0; index < this.TabCount; index++)
{
this.PaintTab(e, index);
}
}
}

private void PaintTab(System.Windows.Forms.PaintEventArgs e, int index)
{
this.PaintTabBackground(e.Graphics, index);
this.PaintTabText(e.Graphics, index);

}

private void PaintTheTabPageBorder(System.Windows.Forms.PaintEventArgs e)
{
if (this.TabCount > 0)
{
Rectangle borderRect = this.TabPages[0].Bounds;
borderRect.Inflate(1, 1);
ControlPaint.DrawBorder(e.Graphics, borderRect,ControlCommon.BorderColor, ButtonBorderStyle.Solid);
}
}

#region Draw TabItem Background
private void PaintTabBackground(System.Drawing.Graphics graph, int index)
{
Rectangle rect = this.GetTabRect(index);


if (index == this.SelectedIndex)
{
if (index == 0)
{
graph.DrawImage(img, new Rectangle(rect.X + 2, rect.Y, rect.Width - 2, 16), new Rectangle(0, 0, 91, 21), GraphicsUnit.Pixel);
}
else
{
graph.DrawImage(img, new Rectangle(rect.X, rect.Y, rect.Width, 16), new Rectangle(0, 0, 91, 21), GraphicsUnit.Pixel);
}
}
else
{
if (index == 0)
{
graph.DrawImage(img, new Rectangle(rect.X + 2, rect.Y, rect.Width - 2, 16), new Rectangle(91, 0, 80, 21), GraphicsUnit.Pixel);
}
else
{
graph.DrawImage(img, new Rectangle(rect.X, rect.Y, rect.Width, 16), new Rectangle(91, 0, 80, 21), GraphicsUnit.Pixel);
}


}
}

#endregion

private void PaintTabText(System.Drawing.Graphics graph, int index)
{
Rectangle rect = this.GetTabRect(index);
Rectangle rect2 = new Rectangle(rect.X + 8, rect.Top + 2, rect.Width - rect.Height, rect.Height);

if (index >= 0)
{
rect2 = new Rectangle(rect.X+8, rect.Top+2, rect.Width - 6, rect.Height);
}
if (index == this.SelectedIndex)
{
if (index >= 0)
{
rect2 = new Rectangle(rect.X + 8, rect.Top, rect.Width - 6, rect.Height);
}
else
{
rect2 = new Rectangle(rect.X + 8, rect.Top , rect.Width - rect.Height, rect.Height);
}
}

string tabtext = this.TabPages[index].Text;
System.Drawing.StringFormat format = new System.Drawing.StringFormat();

format.Alignment = StringAlignment.Near;
format.LineAlignment = StringAlignment.Center;
format.Trimming = StringTrimming.EllipsisCharacter;

SolidBrush forebrush = new SolidBrush(this.ForeColor);
graph.DrawString(tabtext, this.Font, forebrush, rect2, format);
forebrush.Dispose();
}

#region Get Image from Resouce File

protected Bitmap GetResBitmap(string str)
{
Stream sm;
sm = FindStream(str);
if (sm == null) return null;
return new Bitmap(sm);
}

protected Stream FindStream(string str)
{
Assembly assembly = Assembly.GetExecutingAssembly();
string[] resNames = assembly.GetManifestResourceNames();
foreach (string s in resNames)
{
if (s == str)
{
return assembly.GetManifestResourceStream(s);
}
}
return null;
}
#endregion
}
samyou 2010-11-27
  • 打赏
  • 举报
回复
用了其它组件吧
huwen7565833 2010-11-27
  • 打赏
  • 举报
回复

1.自定义控件
robbish 2010-11-27
  • 打赏
  • 举报
回复
dotNetBar
kenriy 2010-11-27
  • 打赏
  • 举报
回复
控件IrisSkin2.dll皮肤控件,效果不是我想要的,因为图是我自己画的,但怎么用代码实现呢?
Microblue 2010-11-27
  • 打赏
  • 举报
回复
去下载ssk文件,直接调用更换皮肤样式,很方便,也很简单~~~
wuyq11 2010-11-27
  • 打赏
  • 举报
回复
kenriy 2010-11-27
  • 打赏
  • 举报
回复


选项卡的箭头如何去掉呢

如何绘制选项卡的背景图呢
加载更多回复(4)

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧