winform 实现类似我们VS工具工具箱那样 对控件分组。

程序漫步 2009-09-07 07:09:20
winform 实现类似我们VS工具工具箱那样 对控件分组。

点击一个栏目 出现该栏目下所以内容。类似我们 VS 工具箱那样的效果。。


怎么实现

就是菜单进行分组吧~~
...全文
629 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
让爱延续 2009-09-08
  • 打赏
  • 举报
回复
哎呦,理解错了lz的意思了 !
还是用NavBarControl吧 忘了那有下载的啦 !
让爱延续 2009-09-08
  • 打赏
  • 举报
回复
lz 这有你想要的控件 分享一下 免费下载的哦!!!


嘿嘿…… 记得给我点分哦!http://www.dotnetmagic.com/downloads/Magic174AndKrypton.zip
程序漫步 2009-09-08
  • 打赏
  • 举报
回复
D
程序漫步 2009-09-08
  • 打赏
  • 举报
回复
D
sugarche 2009-09-08
  • 打赏
  • 举报
回复
还有两个资源文件,一个加号图片(IconResource.expanded),一个减号图片(IconResource.collapsed)。你自己做两张图片加进去
sugarche 2009-09-08
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace SiteView.Ecc.MMC.UserContorls
{

/// <summary>
/// 继承TreeView控件,实现VS工具箱风格
/// </summary>
class ToolBox :TreeView
{

public ToolBox()
{

this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.EnableNotifyMessage, true);

this.ShowLines = false;
this.HotTracking = true;
this.FullRowSelect = true;
this.DrawMode = TreeViewDrawMode.OwnerDrawAll;

this.Nodes.Add("test");
}

/// <summary>
/// 重新DrawNode方法
/// </summary>
/// <param name="e"></param>
protected override void OnDrawNode(DrawTreeNodeEventArgs e)
{

//base.OnDrawNode(e);
if(e.Node.Level == 0)
{
DrawRoot(e);
}
else
{
DrawItem(e);
}

}

/// <summary>
/// 绘制根节点
/// </summary>
/// <param name="e"></param>
private void DrawRoot(DrawTreeNodeEventArgs e)
{

try
{
Rectangle rect = e.Bounds;
rect.Y += 1;
rect.Width -= 1;
rect.Height -= 3;

if(e.Node.IsSelected)
//if (e.State == TreeNodeStates.Marked || e.State == TreeNodeStates.Selected)
{
using (System.Drawing.Brush selBrush = new System.Drawing.SolidBrush(Color.FromArgb(225, 230, 232)))
using (System.Drawing.Pen outerPen = new System.Drawing.Pen(Color.FromArgb(49, 106, 197)))
{
e.Graphics.FillRectangle(selBrush, rect);
e.Graphics.DrawRectangle(outerPen, rect);
}
}
else
{
using (System.Drawing.Drawing2D.LinearGradientBrush lgBrush = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, Color.FromArgb(221, 220, 203), Color.FromArgb(196, 193, 176), LinearGradientMode.Vertical))
using (System.Drawing.Pen linePen = new System.Drawing.Pen(this.BackColor))
{
e.Graphics.FillRectangle(lgBrush, rect);
e.Graphics.DrawLine(linePen, 0, rect.Bottom - 2, rect.Width, rect.Bottom - 2);
}
}
if (e.Node.IsExpanded == true)
{
//e.Graphics.DrawImage(this.imageList3.Images[0], new Point(rect.Left + 3, rect.Top + 4));
e.Graphics.DrawImage(IconResource.expanded, new Rectangle(rect.Left + 3, rect.Top + 4, 10, 10));
}
else
{
e.Graphics.DrawImage(IconResource.collapsed, new Rectangle(rect.Left + 3, rect.Top + 4, 10, 10));
}

rect.Offset(16, 2);
e.Graphics.DrawString(e.Node.Text, new Font("Microsoft Sans Serif", 8.25F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(0))), SystemBrushes.ControlText, rect.Location);
}
catch (Exception ex)
{
//隐藏错误
//log.Error("绘制根节点", ex);
}

}

private System.Drawing.Brush selBrush = new System.Drawing.SolidBrush(Color.FromArgb(175, Color.Gold));
private System.Drawing.Pen pen = SystemPens.HotTrack;
/// <summary>
/// 绘制子结点
/// </summary>
/// <param name="e"></param>
private void DrawItem(DrawTreeNodeEventArgs e)
{

try
{
Rectangle nodeTextRect = e.Bounds;

nodeTextRect.Width -= 1;
nodeTextRect.Height -= 1;

Rectangle rect = e.Bounds;
rect.Inflate(-1, -1);

if (e.Node.IsSelected)
{
e.Graphics.FillRectangle(selBrush, rect);
e.Graphics.DrawRectangle(pen, rect);
}
else
{
e.Graphics.FillRectangle(new System.Drawing.SolidBrush(e.Node.BackColor), e.Bounds);
e.Graphics.DrawRectangle(new System.Drawing.Pen(e.Node.BackColor), e.Bounds);
}

if (this.ImageList != null && e.Node.ImageIndex < this.ImageList.Images.Count)
{
e.Graphics.DrawImage(this.ImageList.Images[e.Node.ImageIndex], new Point(e.Bounds.Left + 3, e.Bounds.Top + 2));
}

nodeTextRect.Offset(20, 3);
e.Graphics.DrawString(e.Node.Text, this.Font, SystemBrushes.ControlText, nodeTextRect.Location);

}
catch (Exception ex)
{
//隐藏错误
//log.Error("绘制子节点", ex);
}

}

}

}


这是我用过的。你自己可以修改一下
sugarche 2009-09-08
  • 打赏
  • 举报
回复
重写treeview控件可以实现。
cc_net 2009-09-08
  • 打赏
  • 举报
回复
我也顺便问下,如果自己写。
每个panle或button下的那些图标,是放到一个form里,点的时候加载
还是怎么做的
程序漫步 2009-09-07
  • 打赏
  • 举报
回复
继续~
TTOJJ 2009-09-07
  • 打赏
  • 举报
回复
1.可以直接分組的控件有listView,treeView
2.像qq一樣的分組:自己用BUTTON或者PANEL寫一個,可以用location貨dock來改變
3.自己寫控件,其實很簡單的,DOWNLOAD點資料就ok了
4.第三方調用,比如DevComponents
程序漫步 2009-09-07
  • 打赏
  • 举报
回复
能推荐下吗~
fengjian_428 2009-09-07
  • 打赏
  • 举报
回复
普通菜单效果不好 用第三方吧

110,534

社区成员

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

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

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