Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何访问usercontrol中的i语句_C#_Winforms_User Controls_If Statement - Fatal编程技术网

C# 如何访问usercontrol中的i语句

C# 如何访问usercontrol中的i语句,c#,winforms,user-controls,if-statement,C#,Winforms,User Controls,If Statement,如何访问用户控件中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 =

如何访问用户控件中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.
     }
}

在这种情况下,我认为发送者将是按钮1,因此它将不可由您的用户控制

您需要一个包含usercontrol的容器(form/panel/…)的引用表单

此外,我知道这可能是为了简单,但你可以改变

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

     return huh; 
} 

您可能还想看看

按控件名称搜索控件 属性并生成所有 匹配的控件


现在发生了什么?现在它只是说“无法将RichTextBox类型转换为MyControl.TextControl”。。。我有点困惑抱歉我按下了向上箭头,但我的鼠标跳了起来,取消了向下的投票:)--我现在正试图引用包含我的用户控件的表单:)谢谢,非常感谢!Control.ControlCollection.Find工作得很好,现在我可以访问正确的控件:)
public bool SendBack(bool huh) 
{
     return huh; 
}