仅在项目的双击事件中编辑TreeCtrl中的标签 [英] Edit Label in TreeCtrl only on double click event of the items
问题描述
在MFC中,在CTreeCtrl 我只想在双击项目文本时编辑标签。单击我不想编辑标签。
In MFC, in CTreeCtrl I want to edit labels only when double clicking the item text.On single click I dont want to edit the label.
如何实现它?
'谢谢。
推荐答案
在对话框编辑器中为树控件设置"编辑标签"样式,并为
添加处理程序 NM_DBLCLK 事件。最简单的实现是'myTree.EditLabel(myTree.GetSelectedItem())',其中
myTree 是控制变量。另一个变体是:
Set the "Edit Labels" style in Dialog Editor for tree control and add a handler for NM_DBLCLK event. The simplest implementation is ‘myTree.EditLabel( myTree.GetSelectedItem() )’, where myTree is the control variable. Another variant is:
void
CMyDialog :: OnNMDblclkTree1(
NMHDR * pNMHDR ,
LRESULT * pResult
)
void CMyDialog::OnNMDblclkTree1( NMHDR *pNMHDR, LRESULT *pResult )
{
CPoint p;
GetCursorPos(& p);
myTree.ScreenToClient(& p);
HTREEITEM h = myTree.HitTest(p);
HTREEITEM h = myTree.HitTest( p );
if (h)
{
if (myTree.EndEditLabelNow(
FALSE ))
{
myTree.SelectItem(h);
myTree.EditLabel(h);
}
}
* pResult
= TRUE ;
}
为了禁用通常的普通默认编辑模式,请尝试以下操作:将一些布尔成员设置为
myTree.EditLabel 之前的
TVN_BEGINLABELEDIT 并按顺序检查布尔值取消标签编辑。
In order to disable the usual normal default editing mode, try this: set some boolean member to true before myTree.EditLabel, then to false after. Handle TVN_BEGINLABELEDIT and check the boolean value in order to cancel the label editing.
这篇关于仅在项目的双击事件中编辑TreeCtrl中的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!