Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 选中/取消选中属性更改上的工具栏按钮_C# - Fatal编程技术网

C# 选中/取消选中属性更改上的工具栏按钮

C# 选中/取消选中属性更改上的工具栏按钮,c#,C#,嗨,我有一个名字叫 public bool ShowLabels{get; set;} 和一个工具栏菜单按钮,用于设置/取消设置ShowLabels值 我希望当ShowLabels属性的值更改时,它也会更改菜单项按钮的检查状态。如何做到这一点为showLabels创建一个真正的私有变量,并展开get;并设置;要成为执行所需操作的方法,请执行以下操作: private bool showLabels; public bool ShowLabels { get {return this.s

嗨,我有一个名字叫

public bool ShowLabels{get; set;}
和一个工具栏菜单按钮,用于设置/取消设置ShowLabels值


我希望当ShowLabels属性的值更改时,它也会更改菜单项按钮的检查状态。如何做到这一点

为showLabels创建一个真正的私有变量,并展开get;并设置;要成为执行所需操作的方法,请执行以下操作:

private bool showLabels;
public bool ShowLabels
{
    get {return this.showLabels; }
    set {
        toolbaritem.property = !toolbaritem.property;
        this.showlabels = value;
    }
}

编写自己的属性访问器来更改菜单按钮的检查状态,而不是“自动”属性。

我还在从工具栏项的单击事件设置ShowLabels的值。这将使用相同的功能-您的ShowLabels=true将调用此设置器,这将适当地影响复选框。