如何刷新由Desginer创建的对象 [英] How to refrence an object created by Desginer

查看:93
本文介绍了如何刷新由Desginer创建的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(我使用的是默认的Visual Studio名称)如何在form1.cs文件(公共局部类Form1:Form中的一个类)中的另一个自定义类中引用texbox对象(texbox1)

(I'm using default Visual Studio names) How can I reference a texbox object(texbox1) in another custom class in form1.cs file(a class within "public partial class Form1 : Form")

这是我的代码。在myclass中,我编写了textBox1,但是intelisense并没有向我建议。我的意思是。在这种情况下,如何使texbox1智能显示?在form1.Desginer.cs中将私有更改为公开不会解决。

here is my code. In myclass I've written textBox1, but intelisense didn't suggest it to me. I mean. what can I do to make texbox1 show up in intelisence in this situation? changing private to public in form1.Desginer.cs does'nt solve it. plaease answer.

namespace Calculator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent(); 
        }


        class myclass 
        {

           textBox1

        }
}


推荐答案

您不能只在嵌套类中引用它作为其一部分 Form1 类,您将必须传递引用

You cant just reference it in your nested class as its part of the Form1 class, you will have to pass in a reference

示例:

class myclass 
{
    public TextBox MyTextBox { get; set; }

    public MyClass(TextBox textbox)
    {
        MyTextBox = textbox;
    }
}

然后在 Form1 类,您在其中创建了 MyClass 实例,可以在 TextBox

Then in your Form1 class where you created the MyClass instance you can pass in your TextBox

MyClass myClass = new MyClass(this.textBox1);

这篇关于如何刷新由Desginer创建的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆