在C#wpf格式中,我想从外部类更改控件的属性(如button.visible = false)。 [英] In C# wpf form, I want to change the properties of the control (like button.visible=false ) from outside class.

查看:165
本文介绍了在C#wpf格式中,我想从外部类更改控件的属性(如button.visible = false)。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

        private void button3_Click(object sender, EventArgs e)
        {
            Form1 fname = new Form1();
            myclass.myctls(fname);
        }
    }
}











我的另一个班级






my another class

namespace WindowsFormsApplication1
{
    class myclass
    {
        public static void myctls(Form f1)
        {
            foreach (Control tempCtrl in f1.Controls)
            {

                    tempCtrl.Enabled = false;
            }
        }
    }
}









请任何人帮助我





Please any one help me

推荐答案

不要。让类包含控件来做它。这样,您可以在不影响外部世界的情况下更改表单。

具体如何操作取决于类之间的关系,但其中一个应该有所帮助:

在两种表格之间传递信息,第1部分:父母对儿童 [ ^ ]

在两个表格之间传递信息,第2部分:儿童到家长 [ ^ ]

在两个表单之间传输信息,第3部分:儿童与儿童 [ ^ ]

示例是Winforms,但原则(实际上相关代码)在WPF中是相同的。
Don't. Let the class containign the control do it. That way, you can change the form without affectign the outside world.
Exqactly how you do it depends on the relation ship between the classes, but one of these should help:
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]
The examples are Winforms, but the principle (and indeed the relevant code) is the same in WPF.


这篇关于在C#wpf格式中,我想从外部类更改控件的属性(如button.visible = false)。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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