DevExpress xtraTabbedMdiManager控件雙擊關(guān)閉MDI標(biāo)簽頁(yè)
DevExpress .net組件包中,有一個(gè)組件是xtraTabbedMdiManager,可以將MDI窗口顯示為T(mén)abControl的樣式,可以說(shuō)非常實(shí)用。可惜的是,關(guān)閉標(biāo)簽頁(yè)(即子MdiChild)不能通過(guò)雙擊來(lái)實(shí)現(xiàn),這對(duì)于用慣了傲游等軟件的朋友來(lái)說(shuō),有點(diǎn)不習(xí)慣。查看xtraTabbedMdiManager的事件,只有MouseDown,MouseUp等,并沒(méi)有DoubleClick,好不爽。
其實(shí),轉(zhuǎn)換一下思路,我們可以將連續(xù)的兩次MouseDown事件模擬成一個(gè)雙擊事件,就可以解決上面的問(wèn)題了,真是一點(diǎn)就破,技術(shù)上沒(méi)有什么難度,且看代碼吧:
在這里,我們認(rèn)為如果兩次點(diǎn)擊時(shí)間間隔小于300毫秒,就認(rèn)為是雙擊。注意,m_LastClick = dt.AddMinutes(-1),這一行代碼的作用是,表示雙擊完成,避免點(diǎn)擊三次認(rèn)為是雙擊了兩次。
上面的代碼還提供了點(diǎn)擊右鏈彈出菜單功能。可以在右鍵菜單中加入你要的功能。
其實(shí),轉(zhuǎn)換一下思路,我們可以將連續(xù)的兩次MouseDown事件模擬成一個(gè)雙擊事件,就可以解決上面的問(wèn)題了,真是一點(diǎn)就破,技術(shù)上沒(méi)有什么難度,且看代碼吧:
//通過(guò)MouseDown事件模擬雙擊關(guān)閉標(biāo)簽頁(yè)
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) //如果兩次點(diǎn)擊的時(shí)間間隔小于300毫秒,則認(rèn)為是雙擊
{
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) //如果兩次點(diǎn)擊的時(shí)間間隔小于300毫秒,則認(rèn)為是雙擊
{
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();
}
}
在這里,我們認(rèn)為如果兩次點(diǎn)擊時(shí)間間隔小于300毫秒,就認(rèn)為是雙擊。注意,m_LastClick = dt.AddMinutes(-1),這一行代碼的作用是,表示雙擊完成,避免點(diǎn)擊三次認(rèn)為是雙擊了兩次。
上面的代碼還提供了點(diǎn)擊右鏈彈出菜單功能。可以在右鍵菜單中加入你要的功能。
posted on 2007-03-14 09:41 西西吹雪 閱讀(3599) 評(píng)論(9) 收藏 舉報(bào)
浙公網(wǎng)安備 33010602011771號(hào)