C# 如何访问usercontrol中的i语句
如何访问用户控件中if语句的结果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 =
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;
}