日期:2014-05-18  浏览次数:20775 次

c# 两个命名空间 控件如何控制
[code=C#]
namespace   用户系统
{
        public   partial   class   Form1   :   Form
        {
                public   Form1()
                {
                        InitializeComponent();

                }
        }
}

namespace   other
{
        class   function1
        {
                private   void   UpdateLab   (string   str)
                {
                        //这里想更改   namepace   用户系统   form1   里一个   Label1.text  
                }
        }
}

[/code]
如何从一个命名空间,更改另外一个命名空间的一个空间属性呢?
又如何读取另一个命名空间内的空间属性呢?

------解决方案--------------------
可以将form1的Label1控件的Modifiers属性设置为public
然后
C# code
namespace other
{
    class function1
    {
        private void UpdateLab (string str)
        {
            //这里想更改 namepace 用户系统 form1 里一个 Label1.text 
            用户系统.Form1 frm1 = new 用户系统.Form1();
            frm1.Label1.Text = str;
        }
    }
}

------解决方案--------------------
(1)将Form1中的Label1定义成public类型的
(2) public function1(Form1 f) { _f = f; }
private Form1 _f;
private void UpdateLab(string str)
{
_f.Label1.text = "xxx";
}
(3)窗体调用:
function1 f1 = new function1(this);
...