Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Okay, how about:</p> <p>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 <code>XmlSerializer</code> into a single folder. Then, you could use something like <code>string[] businessCards = Directory.GetFiles(Path.GetFullPath("mysettings\\businesscards"));</code> to iterate through your long 'cached' list of business cards. Have class that manages adding/removing items from your <code>FlowLayoutPanel</code> by calling a function like: <code>SerializableBusinessCardClass GetNextCard() {}</code>. This would be fairly simple to implement. You could also serialize a <code>List&lt;SerializableBusinessCardClass&gt;</code> 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. </p> <p>Here, I will give you a concrete example of how you would build and serialize such a data structure:</p> <pre><code>public class SerializableBusinessCard { public SerializableBusinessCard() { } public string Name { get; set; } public string Company { get; set; } public List&lt;string&gt; Labels { get; set; } public List&lt;ComboItem&gt; 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&lt;string&gt; Collection{ get; set; } } </code></pre> <p>Usage: </p> <pre><code> public void stackoverflow_BusinessCard_FlowLayoutPanel() { List&lt;string&gt; labels = new List&lt;string&gt;(); 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&lt;string&gt;(); 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&lt;ComboItem&gt; comboItems = new List&lt;ComboItem&gt;(); 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"); } </code></pre> <p>Here is the serialization function:</p> <pre><code> public void SerializeObjectXML(string filename,object obj) { using(StreamWriter streamWriter = new StreamWriter(filename)) { XmlSerializer xmlSerializer = new XmlSerializer(obj.GetType()); xmlSerializer.Serialize(streamWriter,obj); } } </code></pre> <p>Result:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;SerializableBusinessCard xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;Name&gt;CompanyXYZ_BlueTheme&lt;/Name&gt; &lt;Company&gt;CompanyXYZ&lt;/Company&gt; &lt;Labels&gt; &lt;string&gt;Title&lt;/string&gt; &lt;string&gt;Description&lt;/string&gt; &lt;string&gt;Phone&lt;/string&gt; &lt;string&gt;Email&lt;/string&gt; &lt;string&gt;Address&lt;/string&gt; &lt;string&gt;label6&lt;/string&gt; &lt;string&gt;labelN&lt;/string&gt; &lt;/Labels&gt; &lt;ComboBoxes&gt; &lt;ComboItem&gt; &lt;Name&gt;comboName&lt;/Name&gt; &lt;Text&gt;Option1&lt;/Text&gt; &lt;SelectedIndex&gt;0&lt;/SelectedIndex&gt; &lt;Location&gt; &lt;X&gt;50&lt;/X&gt; &lt;Y&gt;265&lt;/Y&gt; &lt;/Location&gt; &lt;size&gt; &lt;Width&gt;100&lt;/Width&gt; &lt;Height&gt;21&lt;/Height&gt; &lt;/size&gt; &lt;Collection&gt; &lt;string&gt;Option1&lt;/string&gt; &lt;string&gt;Option2&lt;/string&gt; &lt;/Collection&gt; &lt;/ComboItem&gt; &lt;/ComboBoxes&gt; &lt;/SerializableBusinessCard&gt; </code></pre> <p>And the deserializer:</p> <pre><code> 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; } </code></pre> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload