转摘自:http://www.cnblogs.com/Along729/archive/2011/03/01/Toolstrip.html
暂时还没时间,把代码分离出来,做到通用,所以大家看着自己动手改改代码吧
看图:
QQ的
美化方法:
ToolStrip 的外观
调用方法
//作者:阿龙(Along) //QQ号:646494711 //QQ群:57218890 //网站:http://www.8timer.com //博客:http://www.cnblogs.com/Along729/ //声明:未经作者许可,任何人不得发布出售该源码,请尊重别人的劳动成果,谢谢大家支持 MainLefttool.Renderer = new Toolstrip(); toolStripButton1.Image = new Bitmap(@"1.png"); toolStripButton2.Image = new Bitmap(@"2.png"); toolStripButton3.Image = new Bitmap(@"3.png"); toolStripButton4.Image = new Bitmap(@"4.png"); toolStripButton5.Image = new Bitmap(@"5.png"); toolStripButton6.Image = new Bitmap(@"6.png"); toolStripButton7.Image = new Bitmap(@"7.png"); toolStripButton8.Image = new Bitmap(@"8.png"); toolStripButton9.Image = new Bitmap(@"panelcenterbtn.png");
重绘Toolstrip的代码
//作者:阿龙(Along) //QQ号:646494711 //QQ群:57218890 //网站:http://www.8timer.com //博客:http://www.cnblogs.com/Along729/ //声明:未经作者许可,任何人不得发布出售该源码,请尊重别人的劳动成果,谢谢大家支持 using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Drawing; using System.Drawing.Drawing2D;
namespace MainForm { public class Toolstrip : ToolStripRenderer { private int i; public Toolstrip() { }
protected override void InitializeItem(ToolStripItem item) { base.InitializeItem(item); item.AutoSize = false; item.Height = 30; item.Padding = new Padding(5); item.Margin = new Padding(0, 0, 0, 1); if (item is ToolStripButton) { ToolStripButton btn = item as ToolStripButton; item.Width =30; }
}
#region //绘制按钮 protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e) { bool chk = false; chk = (e.Item as ToolStripButton).Checked; if (e.Item.Pressed && e.Item.Selected) { i = 2; } else if (e.Item.Selected) { i = 1; } else if (chk) { i = 2; } else { i = 0; } ImageDrawRect.DrawRect(e.Graphics, global::MainForm.Properties.Resources.main_tabbtn, new Rectangle(Point.Empty, e.Item.Size), Rectangle.FromLTRB(5, 15, 5, 5), i, 2); } #endregion }
}
详细测试代码,请进(Winform NET技术交流群:57218890 )群共享下载
暂时还没时间,把代码分离出来,做到通用,所以大家看着自己动手改改代码吧
看图:
QQ的
美化方法:
ToolStrip 的外观
调用方法
//作者:阿龙(Along) //QQ号:646494711 //QQ群:57218890 //网站:http://www.8timer.com //博客:http://www.cnblogs.com/Along729/ //声明:未经作者许可,任何人不得发布出售该源码,请尊重别人的劳动成果,谢谢大家支持 MainLefttool.Renderer = new Toolstrip(); toolStripButton1.Image = new Bitmap(@"1.png"); toolStripButton2.Image = new Bitmap(@"2.png"); toolStripButton3.Image = new Bitmap(@"3.png"); toolStripButton4.Image = new Bitmap(@"4.png"); toolStripButton5.Image = new Bitmap(@"5.png"); toolStripButton6.Image = new Bitmap(@"6.png"); toolStripButton7.Image = new Bitmap(@"7.png"); toolStripButton8.Image = new Bitmap(@"8.png"); toolStripButton9.Image = new Bitmap(@"panelcenterbtn.png");
重绘Toolstrip的代码
//作者:阿龙(Along) //QQ号:646494711 //QQ群:57218890 //网站:http://www.8timer.com //博客:http://www.cnblogs.com/Along729/ //声明:未经作者许可,任何人不得发布出售该源码,请尊重别人的劳动成果,谢谢大家支持 using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Drawing; using System.Drawing.Drawing2D;
namespace MainForm { public class Toolstrip : ToolStripRenderer { private int i; public Toolstrip() { }
protected override void InitializeItem(ToolStripItem item) { base.InitializeItem(item); item.AutoSize = false; item.Height = 30; item.Padding = new Padding(5); item.Margin = new Padding(0, 0, 0, 1); if (item is ToolStripButton) { ToolStripButton btn = item as ToolStripButton; item.Width =30; }
}
#region //绘制按钮 protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e) { bool chk = false; chk = (e.Item as ToolStripButton).Checked; if (e.Item.Pressed && e.Item.Selected) { i = 2; } else if (e.Item.Selected) { i = 1; } else if (chk) { i = 2; } else { i = 0; } ImageDrawRect.DrawRect(e.Graphics, global::MainForm.Properties.Resources.main_tabbtn, new Rectangle(Point.Empty, e.Item.Size), Rectangle.FromLTRB(5, 15, 5, 5), i, 2); } #endregion }
}
详细测试代码,请进(Winform NET技术交流群:57218890 )群共享下载
|
请发表评论