我写了一个用户控件MenuItem,继承自Form Label。我有一个BackgroundWorker线程,其IsBusy属性通过MainForm中的一个属性IsBackgroundBusy公开。如何从MenuItem用户控件中读取此属性?我目前正在使用Application.UseWaitCursor,并在backgroundworker中设置它,它可以完美地工作,但是我不想改变鼠标指针。这就是为什么我觉得设置一个属性会更好。以下是我MainForm中的代码:
这是我的用户控件代码:
public partial class MainForm : Form
{
public bool IsBackgroundBusy
{
get
{
return bwRefreshGalleries.IsBusy;
}
}
这是我的用户控件代码:
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;
}
else
{
this.BackColor = SystemColors.Control;
}
base.OnMouseEnter( e );
}
MainForm
实现并由您的MenuItem
使用的IsBackgroundBusy { get; }
属性。这样,您的MainForm
就不会与您的MenuItem
耦合在一起。 - Anthony