private void setformControlsDefs(formControlsDefData p) { // string sTemp = Assembly.GetExecutingAssembly().Location + ".config"; string sTemp = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\SaisieForestiere10_Form.config"; // MessageBox.Show(sTemp); try { XmlSerializer serializer = new XmlSerializer(typeof(formControlsDefData)); TextWriter textWriter = new StreamWriter(sTemp); serializer.Serialize(textWriter, p); textWriter.Close(); } catch { MessageBox.Show("Erreur lors de l'ecriture du fichier de parametres", "SF10", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void loadFormParams() { try { foreach (Control ctls in this.Controls) { if (ctls.Name != "button1") { this.Controls.Remove(ctls); } } formControlsDef = getformControlsDefs(); Control ctl = new Control(); foreach (fromControlsDefsParams ip in formControlsDef.formControlsDefs) { if (ip.defName == SF10_extMain.m_Parametres.typeSaisie) { switch (ip.controlType) { case "LABEL": ctl = new System.Windows.Forms.Label(); break; case "TEXTBOX": ctl = new System.Windows.Forms.TextBox(); break; case "BUTTON": ctl = new System.Windows.Forms.Button(); break; case "COMBOBOX": ctl = new System.Windows.Forms.ComboBox(); break; case "CHECKBOX": ctl = new System.Windows.Forms.CheckBox(); break; } ctl.Name = ip.controlName; ctl.Text = ip.controlText; ctl.Height = ip.controlSizeHeight; ctl.Width = ip.controlSizeWidth; ctl.Left = ip.controlPositionX; ctl.Top = ip.controlPositionY; ctl.Enabled = ip.controlEnabled; if (ip.controlLookupWhc == null) { ip.controlLookupWhc = ""; } if (ip.controlFontBold) { ctl.Font = new Font(ctl.Font, ctl.Font.Style | FontStyle.Bold); } if (ip.controlEvent != "NULL" && ip.controlEventName != "NULL") { wireUpEvent(ctl, ip.controlEventName, ip.controlEvent); } if (ip.controlLookupTbl != "NULL" && ip.controlLookupFld != "NULL" && ip.controlType == "COMBOBOX") { //C:\Programmes\SaisieForestiere\Tables_Validations_Mrn_NAIPF_2012 Collection<string> g_cLoc = new Collection<string>(); g_cLoc = SF10_clsBase.cGetFromTableTIL(@SF10_extMain.m_Parametres.pathValidation, ip.controlLookupTbl, ip.controlLookupFld, ip.controlLookupFld, ip.controlLookupWhc, "", true); SF10_clsBase.bFillComboBox(ctl as System.Windows.Forms.ComboBox, g_cLoc, true); } this.Controls.Add(ctl); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "SF10", MessageBoxButtons.OK, MessageBoxIcon.Error); } }