小编Roa*_*524的帖子

如何从用户控件中的主窗体中读取属性

我编写了一个用户控件MenuItem,它继承自Form Label.

我有一个backgroundworker线程,其IsBusy属性通过MainForm中的属性公开为IsBackgroundBusy.

如何从MenuItem用户控件中读取此属性?我目前正在使用Application.UseWaitCursor,我在backgroundworker中设置它并且它完美地工作,但是我不希望光标改变.这就是为什么我认为我可以设置的房产会好得多.

这是我的MainForm中的代码:

public partial class MainForm : Form
{
    public bool IsBackgroundBusy
    {
        get
        {
            return bwRefreshGalleries.IsBusy;
        }
    }
Run Code Online (Sandbox Code Playgroud)

这是我的usercontrol的代码:

public partial class MenuItem: Label
{
    private bool _disableIfBusy = false;

    [Description("Change color if Application.UseWaitCursor is True")]
    public bool DisableIfBusy
    {
        get
        {
            return _disableIfBusy;
        }

        set
        {
            _disableIfBusy = value;
        }
    }

    public MenuItem()
    {
        InitializeComponent();
    }

    protected override void OnMouseEnter( EventArgs e )
    {
        if ( Application.UseWaitCursor && _disableIfBusy )
        {
            this.BackColor = SystemColors.ControlDark;
        } …
Run Code Online (Sandbox Code Playgroud)

c# user-controls winforms

5
推荐指数
1
解决办法
191
查看次数

标签 统计

c# ×1

user-controls ×1

winforms ×1