[Solved] How to reuse a form ( and change its context when needed) to avoid multiple identical forms? C# [closed]


Why do you need a new form class for each country? The idea of a class is that it holds common behaviours. A form is a class. just instantiate an instance of the class with the data that it needs to display. Create a data class to encapsulate the data that the form shows (like map image, description, history etc) and pass that class to the form before showing it.
eg:

public class Country
{
    public string Name {get;set;}
    public string Description {get;set;}
    public string MapUrl {get;set;}
    public string History {get;set;}
    //any other properties you need to set. Get these from a database or text file if you want
}

in the form add a method like the following:

public void SetCountry(Country country)
{
    //assumung you have controls on your form for displaying the data:
    Text = country.Name;
    txtDescription.Text = country.Description;
    txtHistory.Text = country.History;
    //etc.
}

4

solved How to reuse a form ( and change its context when needed) to avoid multiple identical forms? C# [closed]