Winforms Designer: Modify (and keep) properties in sub objects

帅比萌擦擦* 提交于 2019-12-06 14:00:46

问题


For a WinForms control, I'd like to move certain settings into a sub object. One of them is a custom class containing all UI Strings, the other a OpenFileDialog:

class MyControl: Control
{
  // ...
  private OpenFileDialog m_dlgOpen = new OpenFileDialog();
  public OpenFileDialog DialogOpen
  {
     get { return m_dlgOpen; }
  }
}

This adds the sub object to the designer, and allows to edit its properties (e.g. title, default extension, filter). However, the changes are nto added to the InitalizeComponent method, so they are lost.

Is it possible to make this properties "persist" in the InitializeComponent method?


回答1:


Tell the designer to serialize the object itself:

  [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  public OpenFileDialog DialogOpen {
    get { return m_dlgOpen; }
  }


来源:https://stackoverflow.com/questions/600759/winforms-designer-modify-and-keep-properties-in-sub-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!