c# - Dynamic Windows form - list with XML -


i creating dynamic form if click on "add", new panel appears set of buttons.

in panel, add list remember how many buttons created. thought realize list, want increment again though restart console.

may there tip put in xmlfile. in way strategy can renamed max of present in csv, not know how record , how increment...

any idea?

public class serialstrategyfuture {     public string strategyname { get; set; }     public string numstrategy { get; set; } }  public void createstrategyfuture() {     consolestrategyitem strategyitemfuture = new consolestrategyitem();     strategyitemfuture.location = new point(3, 3);     futurecontainer.height += 85;     futurecontainer.controls.add(strategyitemfuture);      serialstrategyfuture strategyfuture = new serialstrategyfuture();     strategyfuture.strategyname = "strat future ";     strategyfuture.numstrategy = "how increment ???";     xmlserializer serializer = new xmlserializer(typeof(serialstrategyfuture));     textwriter textwriter = new streamwriter(@"c:\users\...");     serializer.serialize(textwriter,strategyfuture);     textwriter.close();      consolestrategyitem.instance.txtstrategyname.text = "strat future 1 "; } 

i not sure if can serialize uturecontainer.controls list. threfore, use way:

  1. declare list ouf buttons:

    list controllist = new list();

  2. each time users creates new button: controllist.add(strategyitemfuture);

  3. serialize list when program closes or opportune moment:
  4. deserialize when program starts.
  5. build foreach loop pulls buttons deserialized list.

here 2 methods use serialize / deserialize

/// <summary> /// serializes file compressed xml file. if error occurs, exception not caught. /// </summary> /// <typeparam name="t">the type</typeparam> /// <param name="obj">the object.</param> /// <param name="filename">name of file.</param> public static void serializetoxml<t>(t obj, string filename) {     try     {         xmlserializer serializer = new xmlserializer(typeof(t));          using (filestream fs = new filestream(filename, filemode.create))         {             using (gzipstream compressor = new gzipstream(fs, compressionmode.compress))             {                 serializer.serialize(compressor, obj);             }         }     }     catch (exception)     {         throw;     } }  /// <summary> /// deserializes object xml. /// </summary> /// <typeparam name="t">the object</typeparam> /// <param name="file">the file.</param> /// <returns> /// deserialized object /// </returns> public static t deserializefromxml<t>(string file) {     t result;     xmlserializer ser = new xmlserializer(typeof(t));     using (filestream fs = new filestream(file, filemode.open))     {         using (gzipstream decompressor = new gzipstream(fs, compressionmode.decompress))         {             result = (t)ser.deserialize(decompressor);             return result;         }     } } 

}

usage: serializetoxml(controllist , yourpath);   this.controllist = deserializefromxml<list<consolestrategyitem>>(yourpath); 

i doing little bit more storing number of buttons, has advantage can store more data when buttons have more logic.


Comments