其实,转换一下思路,我们可以将连续的两次MouseDown事件模拟成一个双击事件,就可以解决上面的问题了,真是一点就破,技术上没有什么难度,且看代码吧:
//
通过MouseDown事件模拟双击关闭标签页
private DateTime m_LastClick = System.DateTime.Now;
private void xtraTabbedMdiManager1_MouseDown( object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
DateTime dt = DateTime.Now;
TimeSpan span = dt.Subtract(m_LastClick);
if (span.TotalMilliseconds < 300 ) // 如果两次点击的时间间隔小于300毫秒,则认为是双击
{
if ( this .MdiChildren.Length > 1 )
{
if ( this .ActiveMdiChild != m_MapForm)
{
this .ActiveMdiChild.Close();
}
}
m_LastClick = dt.AddMinutes( - 1 );
}
else
m_LastClick = dt;
}
else if (e.Button == MouseButtons.Right)
{
// 弹出右键菜单
if ( this .ActiveMdiChild != m_MapForm)
{
POINTAPI pt = new POINTAPI();
GetCursorPos( ref pt);
System.Drawing.Point p = new System.Drawing.Point(pt.x, pt.y);
popMenuCloseTab.ShowPopup( this .barManager1, p);
}
}
}
private void mnuCloseTab_ItemClick( object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if ( this .ActiveMdiChild != m_MapForm)
{
this .ActiveMdiChild.Close();
}
}
private DateTime m_LastClick = System.DateTime.Now;
private void xtraTabbedMdiManager1_MouseDown( object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
DateTime dt = DateTime.Now;
TimeSpan span = dt.Subtract(m_LastClick);
if (span.TotalMilliseconds < 300 ) // 如果两次点击的时间间隔小于300毫秒,则认为是双击
{
if ( this .MdiChildren.Length > 1 )
{
if ( this .ActiveMdiChild != m_MapForm)
{
this .ActiveMdiChild.Close();
}
}
m_LastClick = dt.AddMinutes( - 1 );
}
else
m_LastClick = dt;
}
else if (e.Button == MouseButtons.Right)
{
// 弹出右键菜单
if ( this .ActiveMdiChild != m_MapForm)
{
POINTAPI pt = new POINTAPI();
GetCursorPos( ref pt);
System.Drawing.Point p = new System.Drawing.Point(pt.x, pt.y);
popMenuCloseTab.ShowPopup( this .barManager1, p);
}
}
}
private void mnuCloseTab_ItemClick( object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if ( this .ActiveMdiChild != m_MapForm)
{
this .ActiveMdiChild.Close();
}
}
在这里,我们认为如果两次点击时间间隔小于300毫秒,就认为是双击。注意,m_LastClick = dt.AddMinutes( - 1 ),这一行代码的作用是,表示双击完成,避免点击三次认为是双击了两次。
上面的代码还提供了点击右链弹出菜单功能。可以在右键菜单中加入你要的功能。