Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I force the changes in base class fields to be serialized via a base class property in the inherited type's designer?

Sometimes you might want to let the designer serializer serialize the changes in base fields via a property rather than the field itself using the AccessedThroughProperty attribute in the System.Runtime.CompilerServices namespace.

public class CustomForm : Form 
{ 
  [ AccessedThroughProperty( "CustomList" ) ] 
  private ArrayList customList; 
      
  public ArrayList CustomList 
  {
    get { return customList; } 
  }
}  

Then when the above form is inherited and items get added to the inherited form's designer, code will be added as follows in the inherited form's InitializeComponent:

private void InitializeComponent() 
{ 
// ...
this.CustomList.Add( aNewItem ); 
} 

Contributed from George Shepherd's Windows Forms FAQ



Page view counter