gpt4 book ai didi

c# - 如何访问用户控件中的 i 语句

转载 作者:太空宇宙 更新时间:2023-11-03 14:31:56 24 4
gpt4 key购买 nike

如何在用户控件中访问 if 语句的结果?

UserControl code:

public bool SendBack(bool huh)
{
if(huh)
huh = true;
else huh = false;

return huh;
}

在一个单独的项目中,我试图像这样访问它:

private void button1_Click(object sender, EventArgs e)
{
MyControl.TextControl t = (MyControl.TextCOntrol)sender;
if(t.SendBack(true))
{
// Do something.
}
}

最佳答案

在这种情况下,我认为发送者将是 button1,因此它不会被转换为您的用户控件...

您将需要一个包含您的用户控件的容器(表单/面板/...)的引用。

此外,我知道这可能是为了简单起见,但您可以更改

public bool SendBack(bool huh) 
{
if(huh)
huh = true;
else huh = false;

return huh;
}

public bool SendBack(bool huh) 
{
return huh;
}

您可能还想看看 Control.ControlCollection.Find Method

Searches for controls by their Name property and builds an array of all the controls that match.

关于c# - 如何访问用户控件中的 i 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2408825/

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