禁用下一个表单中的按钮 [英] Disabling buttons in the next form

查看:33
本文介绍了禁用下一个表单中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有 form1 和 form2.form1是登录页面,登录后进入form2.我还使用用户名和密码为 form1 创建了一个数据库表,其中 admin 和 user 作为 2 个实体和相关记录.其中 form2 包含 2 个按钮管理员和用户.问题是.. 当我以管理员身份登录时,我希望启用 form2 中的所有按钮..当以用户身份登录时,我只希望启用用户按钮并禁用管理员.请任何人都可以帮助我进行此编码..?

I have form1 and form2 in my project. form1 is login page, after logging I get into form2. I have also created a database table for form1 with username and password, with admin and user as 2 entities and related records too. where form2 contains 2 buttons admin and users. the question is.. when i log in as an admin i want all the buttons in form2 enabled..when logged in as user i only want users button to be enabled and admin to be disabled. please could anyone help me with this coding ..?

推荐答案

正如 TaW 所说,form2 的 flag 参数构造函数应该运行.

As TaW said, the flag parameter in form2's constructor should run.

另一种可能是在form2中创建一个属性:

Another possibility is to create a property in form2:

    private bool isAdmin;

    public bool IsAdmin
    {
        get
        {
            return isAdmin;
        }

        set
        {
            isAdmin = value;
            btnAdmin.Enabled = isAdmin;
        }
    }

并在显示form2之前在form 1中使用它.对于管理员:

and use it in form 1 before you show form2. For an admin:

    var f = new Form2 { IsAdmin = true };
    f.Show();

对于普通用户:

    var f = new Form2 { IsAdmin = false };
    f.Show();

希望有帮助.

这篇关于禁用下一个表单中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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