mirror of
https://github.com/ClassicDIY/ModbusTool.git
synced 2026-10-19 06:20:52 +08:00
59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using Modbus.Common.Properties;
|
|
|
|
namespace Modbus.Common
|
|
{
|
|
public delegate bool PreRemoveTab(int indx);
|
|
public class TabControlEx : TabControl
|
|
{
|
|
public TabControlEx()
|
|
: base()
|
|
{
|
|
PreRemoveTabPage = null;
|
|
this.DrawMode = TabDrawMode.OwnerDrawFixed;
|
|
}
|
|
|
|
public PreRemoveTab PreRemoveTabPage;
|
|
|
|
protected override void OnDrawItem(DrawItemEventArgs e)
|
|
{
|
|
var r = GetTabRect(e.Index);
|
|
r.Offset(2, 2);
|
|
r.Width = 10;
|
|
r.Height = 10;
|
|
e.Graphics.DrawIcon(Resources.close, r);
|
|
e.Graphics.DrawString(TabPages[e.Index].Text, e.Font, Brushes.Black, new PointF(r.X + 10, r.Y));
|
|
e.DrawFocusRectangle();
|
|
}
|
|
protected override void OnMouseClick(MouseEventArgs e)
|
|
{
|
|
Point p = e.Location;
|
|
for (int i = 0; i < TabCount; i++)
|
|
{
|
|
Rectangle r = GetTabRect(i);
|
|
r.Width = 10;
|
|
if (r.Contains(p))
|
|
{
|
|
CloseTab(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void CloseTab(int i)
|
|
{
|
|
if (PreRemoveTabPage != null)
|
|
{
|
|
bool closeIt = PreRemoveTabPage(i);
|
|
if (!closeIt)
|
|
return;
|
|
}
|
|
TabPages.Remove(TabPages[i]);
|
|
}
|
|
}
|
|
}
|