一.引子
这个控件是追求UI美化功能的产物.效果类似于VS2003的ToolBox,虽然程序的实现方法,功能与效率是软件追求的目标,不过,商业化的软件,缺乏美感总显得不那么专业.
二.设计时效果
三.运行时效果
四.谈谈主要的实现思路
应该说,这个控件的实现方法与我以前的文章JCSTOOLBOX很相似,只是在布局,以及超出部分的调整上有所不同.因为控件采用完全绘制的方法实现,所以效率很高.对于每个子项的图标采用了32X32的大小.提供了子项被选中,子项变化,单击,双击等事件.
如果哪位朋友对购买完整的源代码感兴趣,可以参看"控件源码收费表",或者发邮件给我.当然,也欢迎大家对实现方法的技术讨论.
五.部分源代码
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Drawing;
using
System.Data;
using
System.Text;
using
System.Windows.Forms;
namespace
JCSControlLibary.JcsToolList
...
{
[DefaultEvent("ItemDoubleClick")]
public partial class JcsToolList : UserControl
...{
public JcsToolList()
...{
InitializeComponent();
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.ResizeRedraw, true);
this.Padding = new Padding(0, 25 + 1, 8, 7);
_closebutton = new Rectangle(6, 4, 16, 16);
_vScrollBar = new VScrollBar();
_vScrollBar.Dock = DockStyle.Right;
this.Controls.Add(_vScrollBar);
RefreshScrollBar();
}
private Int32 _itemHeight = 60; //item的高
private Int32 _categoryHeight = 22;//分类项的高
private Int32 _itemBeginTop = 26;
private Int32 _itemSpace = 0;//item间隔
private const Int32 _categoryLeft = 6;//文字左侧间隔
private const Int32 _itemleft = 6;
private Rectangle _closebutton;
private VScrollBar _vScrollBar;
private JcsToolListCategoryCollection _categories = new JcsToolListCategoryCollection();
private ImageList _imagelist;
private JcsToolListCategory _selectedCateGory;
private JcsToolListItem _selectedItem = null;//选择的ITEM
private HitTestType _hittest = HitTestType.None ;
private enum HitTestType
...{
CateGray,
Item,
CateGrayDown,
CateGrayUp,
Title,
None
}
public delegate void ItemChangedEventHandler(Object sender, EventArgs e);
public event ItemChangedEventHandler ItemChanged;
public event EventHandler ItemClick;
public event EventHandler ItemDoubleClick;

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Category("Jcs属性"), Description("分组项的集合")]
public JcsToolListCategoryCollection Categories
...{
get
...{
return _categories;
}
set
...{
_categories = value;
}
}
[Category("Jcs属性"), Description("分组项的图标集合对象")]
public ImageList ImageList
...{
get ...{ return this._imagelist; }
set ...{ this._imagelist = value; }
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public JcsToolListCategory SelectedCateGory
...{
get
...{
return _selectedCateGory;
}
set
...{
if (value != _selectedCateGory)
...{
if (_selectedCateGory != null)
...{
_selectedCateGory.IsOpen = !_selectedCateGory.IsOpen;
//_selectedCateGory.IsShowButton = false;
}
_selectedCateGory = value;
}
else
...{
_selectedCateGory = null;
}
this.Invalidate();
}
}
public JcsToolListItem SelectedItem
...{
get ...{ return _selectedItem; }
set
...{
if (value != _selectedItem)
...{
_selectedItem = value;
if (ItemChanged != null)
ItemChanged(_selectedItem, new EventArgs());
this.Invalidate();
}
}
}
3971

被折叠的 条评论
为什么被折叠?



