gpt4 book ai didi

c# - 在 TreeView 中编辑节点时删除背景

转载 作者:行者123 更新时间:2023-11-30 17:02:36 25 4
gpt4 key购买 nike

当我编辑树节点(长名称)时,它有一个背景颜色:

enter image description here

如何删除背景?如何更改背景颜色?

我试图在 OnDrawNode 中删除它,但这是不可能的。接下来,我尝试使用 TVM_GETEDITCONTROL 消息并发送 WM_CTLCOLOREDIT,但它也不起作用:

    [DllImport("user32.dll")]
internal static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

internal const int WM_CTLCOLOREDIT = 0x0133;
internal const int TVM_GETEDITCONTROL = 0x110F;

private void NodeTree_BeforeLabelEdit(object sender, NodeLabelEditEventArgs e)
{
TreeNode nodeEditing = e.Node;
IntPtr editControlHandle = SendMessage(NodeTree.Handle, (uint)TVM_GETEDITCONTROL, IntPtr.Zero, IntPtr.Zero);
if (editControlHandle != IntPtr.Zero)
{
SendMessage(editControlHandle, (uint)WM_CTLCOLOREDIT, ColorTranslator.ToWin32(Color.Red), new IntPtr(1));
}
}

最佳答案

This background - 选中节点的背景。在 BeforeLabelEdit 我取消订阅 AfterSelect 的事件中,记住所选节点并取消选择节点:

private TreeNode SelectedNodeBeforeEdit;

private void NodeTree_BeforeLabelEdit(object sender, NodeLabelEditEventArgs e)
{
NodeTree.AfterSelect -= NodeTree_AfterSelect;
SelectedNodeBeforeEdit = NodeTree.SelectedNode;
NodeTree.SelectedNode = null;
}

在 AfterLabelEdit 事件中,我订阅 AfterSelect 并显示所选节点:

private void NodeTree_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
{
NodeTree.SelectedNode = SelectedNodeBeforeEdit;
NodeTree.AfterSelect += NodeTree_AfterSelect;
}

关于c# - 在 TreeView 中编辑节点时删除背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19584130/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com