gpt4 book ai didi

c# - 将 TreeView on click 事件执行到另一个 click 事件中

转载 作者:太空宇宙 更新时间:2023-11-03 12:12:27 25 4
gpt4 key购买 nike

我有一个TreeView 的方法。当我点击父 Item 时,它执行如下方法:

private void tvProjectList_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
//code there
}

我的问题是:
如何将此方法执行到另一个点击事件中,例如:

private void dgvTaskAssign_CellClick(object sender, DataGridViewCellEventArgs e)
{
tvProjectList_NodeMouseClick()
}

我如何将发件人发送到那里并请求 TreeNodeMouseClickEventArgs

最佳答案

您可以使用 Control.Invoke 的魔法调用事件方法/Control.BeginInvoke (我在这里引用别人的话),使用 MethodInvoker Delegate .这将执行其代码。

您还可以在事件方法特定的 EventArgs 中传递一些参数,创建该事件参数类型的新实例。

像这样:

private void dgvTaskAssign_CellClick(object sender, DataGridViewCellEventArgs e)
{
treeView1.Invoke((MethodInvoker)delegate {
tvProjectList_NodeMouseClick(this,
new TreeNodeMouseClickEventArgs(tvProjectList.SelectedNode, MouseButtons.Left, 1, 0, 0));
});
}

private void tvProjectList_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
MessageBox.Show("Why did you click me this way!");
}

但您可能应该考虑 Ctznkane525 在他的回答中提出的建议。

关于c# - 将 TreeView on click 事件执行到另一个 click 事件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51432345/

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