Okay, how about:
Create a class to store the information necessary to recreate a business card (10 labels and 3 comboboboxes) as public, gettable/settable properties, and with an empty default public constructor. Then, serialize each business card as an xml (or binary) file using XmlSerializer
into a single folder. Then, you could use something like string[] businessCards = Directory.GetFiles(Path.GetFullPath("mysettings\\businesscards"));
to iterate through your long 'cached' list of business cards. Have class that manages adding/removing items from your FlowLayoutPanel
by calling a function like: SerializableBusinessCardClass GetNextCard() {}
. This would be fairly simple to implement. You could also serialize a List<SerializableBusinessCardClass>
with a length of about 5 (or however many you wanted to load in at once) to a single XML file for maximum efficiency, or if you have a truly ridiculous amount of business cards (such that explorer lags when browsing the folder). While a binary serialization would be faster, the XML approach has the added benefit that your clients can specify new business cards they want you to display by creating the XML file yourself.
Here, I will give you a concrete example of how you would build and serialize such a data structure:
public class SerializableBusinessCard
{
public SerializableBusinessCard() { }
public string Name { get; set; }
public string Company { get; set; }
public List<string> Labels { get; set; }
public List<ComboItem> ComboBoxes { get; set; }
}
public class ComboItem
{
public ComboItem() { }
public string Name { get; set; }
public string Text { get; set; }
public int SelectedIndex { get; set; }
public Point Location { get; set; }
public Size size { get; set; }
public List<string> Collection{ get; set; }
}
Usage:
public void stackoverflow_BusinessCard_FlowLayoutPanel()
{
List<string> labels = new List<string>();
labels.Add("Title");
labels.Add("Description");
labels.Add("Phone");
labels.Add("Email");
labels.Add("Address");
labels.Add("label6");
labels.Add("labelN");
ComboItem cItem = new ComboItem();
cItem.Collection = new List<string>();
cItem.Collection.Add("Option1");
cItem.Collection.Add("Option2");
cItem.Name = "comboName";
cItem.SelectedIndex = 0;
cItem.Text = cItem.Collection[cItem.SelectedIndex];
cItem.Location = new Point(50, 265);
cItem.size = new Size(100,21);
List<ComboItem> comboItems = new List<ComboItem>();
comboItems.Add(cItem);
SerializableBusinessCard bCard1 = new SerializableBusinessCard();
bCard1.Name = "CompanyXYZ_BlueTheme";
bCard1.Company = "CompanyXYZ";
bCard1.Labels = labels;
bCard1.ComboBoxes = comboItems;
SerializeObjectXML("BusinessCard_392.xml",bCard1);
SerializableBusinessCard loaded = DeserializeBusinessCardXML("BusinessCard_392.xml");
}
Here is the serialization function:
public void SerializeObjectXML(string filename,object obj)
{
using(StreamWriter streamWriter = new StreamWriter(filename))
{
XmlSerializer xmlSerializer = new XmlSerializer(obj.GetType());
xmlSerializer.Serialize(streamWriter,obj);
}
}
Result:
<?xml version="1.0" encoding="utf-8"?>
<SerializableBusinessCard xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Name>CompanyXYZ_BlueTheme</Name>
<Company>CompanyXYZ</Company>
<Labels>
<string>Title</string>
<string>Description</string>
<string>Phone</string>
<string>Email</string>
<string>Address</string>
<string>label6</string>
<string>labelN</string>
</Labels>
<ComboBoxes>
<ComboItem>
<Name>comboName</Name>
<Text>Option1</Text>
<SelectedIndex>0</SelectedIndex>
<Location>
<X>50</X>
<Y>265</Y>
</Location>
<size>
<Width>100</Width>
<Height>21</Height>
</size>
<Collection>
<string>Option1</string>
<string>Option2</string>
</Collection>
</ComboItem>
</ComboBoxes>
</SerializableBusinessCard>
And the deserializer:
public static SerializableBusinessCard DeserializeBusinessCardXML(string filename)
{
SerializableBusinessCard result = new SerializableBusinessCard();
using(StreamReader streamReader = new StreamReader(filename))
{
XmlSerializer xmlReader = new XmlSerializer(typeof(SerializableBusinessCard));
result = (SerializableBusinessCard) xmlReader.Deserialize(streamReader);
}
return result;
}
Hope this helps.