简体   繁体   English

Visual Studio-从设计器窗口中删除自定义控件

[英]visual studio - remove custom control from designer window

I have a user control panel that has two buttons on it. 我有一个用户控制面板,上面有两个按钮。 Other user controls inherit from this control and set a property to true if the buttons should be visible. 其他用户控件将从该控件继承,并且如果按钮应该可见,则将属性设置为true。 Everything runs how I want it to but what I'm looking for is a way to clear these buttons from the designer window for forms where this property is left at false. 一切都按我想要的方式运行,但是我正在寻找的是从设计器窗口中清除这些按钮的方法,该表单的此属性保留为false。

looks like: 看起来像:

[DefaultValue(false)]
public bool ShowButtons{
  set
  { 
    mShowButtons = value;
    UpdateButtons();
  }
  get
  {
    return mShowButtons;
  }
}

This property shows in the properties window and the buttons are always shown in the designer window. 此属性显示在属性窗口中,而按钮始终显示在设计器窗口中。 Is there some way to have the designer evaluate this when the property is changed to get the buttons to clear from the inheriting form? 当更改属性以使按钮可以从继承表单中清除时,是否可以通过某种方法让设计人员对此进行评估? I was unable find a designer attribute to do this. 我找不到设计器属性来执行此操作。

Try adding a get : 尝试添加get

bool mShowButtons;
[DefaultValue(false)]
public bool ShowButtons
{
  get
  {
     return mShowButtons;
  }
  set
  { 
    mShowButtons = value;
    UpdateButtons();
  }
}

Now when editing your derived class in the Designer, you should be able to see a ShowButtons property in properties window when the derived UserControl is selected. 现在,当在设计器中编辑派生类时,选择派生UserControl时,应该可以在属性窗口中看到ShowButtons属性。 (It will be in the "Misc" section unless you add the appropriate attribute). (除非添加适当的属性,否则它将在“其他”部分中)。 If you set it there, it should have the appropriate affect in the Designer (Assuming the contents of the UpdateButtons() function work correctly)). 如果在此处进行设置,它将在设计器中产生适当的影响(假定UpdateButtons()函数的内容正常工作)。

A property must be public and have bot get and set in order to display in the Properties editor window. 为了显示在“属性编辑器”窗口中,一个属性必须是公共的,并且必须setget漫游器。 Once it is, then setting the value in the properties window will "save" that setting for the designed control in the control's resources/implementation. 一旦设置好,然后在属性窗口中设置该值将在控件的资源/实现中“保存”该设计控件的设置。

I use this functionality quite often to specialize derived UserControls, so I know it should work for you (although there may be other issues at play). 我经常使用此功能来专门化派生的UserControl,因此我知道它应该对您有用(尽管可能还有其他问题在起作用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Xamarin Android,自定义控件和Visual Studio设计器 - Xamarin Android, custom control and Visual Studio designer 自定义控件不会在Visual Studio Designer中更新 - Custom Control Doesn't Update in Visual Studio Designer Visual Studio 2019 winforms 自定义控件设计器问题 - Visual Studio 2019 winforms custom control designer problem 使用自定义ContentPropertyAttribute时,Visual Studio Designer显示空窗口 - Visual Studio Designer shows empty Window when using custom ContentPropertyAttribute 如何从 Visual Studio 中的 WinForms 设计器设置父控件? - How to set the Parent Control from WinForms Designer in Visual Studio? 从设计器中隐藏WPF控件的属性(Visual Studio 2010) - Hiding a property of a WPF control from the Designer (Visual Studio 2010) 从Visual Studio Designer /属性窗口中隐藏继承的公共属性 - Hide Inherited Public Property from Visual Studio Designer / Properties Window 使用自定义设计器扩展Visual Studio - Extending Visual Studio with a Custom Designer Visual Studio 2022 winform 设计器不在任何控件的属性 window 中显示 ApplicationSettings - Visual Studio 2022 winform designer does not show ApplicationSettings in the property window of any control Visual Studio设计器属性窗口与设计器文件 - Visual studio designer property window vs designer file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM