一.设计时效果
二.运行时效果
三.简单谈谈实现思路
应该说这是一个绘制窗体管理样式的控件.由2个部分组成.一部分就是绘制窗体名称的控件,另一部分就是显示窗体的Panel,在这个Panel中,我们将Form以Toplevel = false的设置后加入Panel中.同时,根据对一个Form集合的循环来绘制出这些窗体的显示标题,并通过判断鼠标点击位置来获得当前选中的Form,同时,我们还根据FirstVisbleForm来判断哪个FORM的绘制部分要显示出来哪些不需要显示出来.
四.部分源代码
public partial class JcsFormHeader : UserControl
{
public JcsFormHeader()
{
InitializeComponent();
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.Selectable, true);
this.Height = DEF_HEADER_HEIGHT;
_list = new List<Form>();
_menu = new ContextMenuStrip();
_menu.ItemClicked += new ToolStripItemClickedEventHandler(_menu_ItemClicked);
_closeButton = new FormCloseButton(render);
_menuGlyph = new FormMenuGlyph(render);
_menuGlyph.Bounds = new Rectangle(ClientSize.Width - DEF_GLYPH_WIDTH, 2, 16, 16);
_closeButton.Bounds = new Rectangle(ClientSize.Width - 20, 2, 16, 16);
SetDefaultSelected();
}
private ToolStripProfessionalRenderer render = new ToolStripProfessionalRenderer();
private int _defaultStartPosition = 10 ;
private const int DEF_HEADER_HEIGHT = 24;//默认的HEADER的高
private const int DEF_GLYPH_WIDTH = 40;//默认的HEADER的宽
private Rectangle _stripButtonRect = Rectangle.Empty;//Button的区域
private List<Form> _list;
private StringFormat sf = null;//文本布局类型
private ContextMenuStrip _menu;
private FormMenuGlyph _menuGlyph = null;//控制菜单
private FormCloseButton _closeButton = null;//关闭按钮
//private TabLeftMoveButton LeftmoveButton = null;//左移动按钮
private Form _selectedForm = null;
private Form _firstForm = null;
private bool _showMenu = true;
private bool _showClose = true;
public enum HitTestResult
{
CloseButton,//关闭按钮
MenuGlyph,//控制菜单
LeftMoveButton,
RightMoveButton,
Form,//ITEM
None//其他任何地区
}
public Form SelectedForm
{
get { return _selectedForm; }
set
{
if (_selectedForm != value)
{
//if(_selectedForm!=null)
// _selectedForm.SendToBack();
_selectedForm = value;
this.Invalidate();
//_selectedForm.Show();
_selectedForm.BringToFront();
}
}
}