Petit pb avec C#
Résoluvoila j'ai declaré et initialisées mes variables (controles) , puis mis a jour les controles mais lors de l'exécution sur mon interfaçe il n ya pas les valeurs initiales correspondantes, voici le bout de code pour mieux comprendre :
//declaration
private double pasApp = 0.1;
private double moment = 0.0;
private double sigmoidBeta = 2.0;
private double errAppLimite = 0.1;
private int nbrepoque = 200;
// Mettre à jour les controles de l'application
private void UpdateSettings()
{
pasAppBox.Text = pasApp.ToString();
momentBox.Text = moment.ToString();
nbepoq.Text = nbrepoque.ToString();
sigmoidBetaBox.Text = sigmoidBeta.ToString();
errAppLimiteBox.Text = errAppLimite.ToString();
}
// Enable/disable controls
private void EnableControls(bool enable)
{
pasAppBox.Enabled = enable;
momentBox.Enabled = enable;
sigmoidBetaBox.Enabled = enable;
errAppLimiteBox.Enabled = enable;
button1.Enabled = enable;
}
ai je oublier quelque chose?, merci d'avance
24 réponses
Le problème porte sur l’absence des valeurs initiales dans les contrôles texte malgré l’initialisation des variables privées et l’appel supposé de UpdateSettings pour afficher ces valeurs au démarrage. Des éléments de la discussion indiquent qu’il faut appeler UpdateSettings au chargement de la fenêtre et vérifier que le nom et l’emplacement de la méthode soient bien raccordés à l’événement. D’autres échanges soulignent que les gestionnaires TextChanged réécrivent systématiquement le texte des boîtes, empêchant l’affichage des valeurs initiales et provoquant des incohérences entre texte affiché et variables internes. En pratique, plusieurs suggèrent de retirer ou d’adapter ces gestionnaires, puis d’assurer l’initialisation via UpdateSettings dès la construction ou le chargement, afin que les contrôles reflètent les valeurs dès le départ.
-
Bonjour,
Ben moi aussi ça marche trés bien maintenant,
Merci a tous ^^ -
bonjour,
moi aussi ça marche très bien ^_^ -
Chez moi elles se remplissent c'est curieux :)
-
Bonjour,
Alors j'ai lut ton premier message et j'ai survolé les autres, voilà chez moi ce qui ne fonctionnait pas lors de ton premier message est réglé.
Voici le projet zippé :
http://demango.ovh.org/wfa1.zip -
Et la fonction
private void Form1_Load(object sender, EventArgs e)
{
pasAppBox.Text = pasApp.ToString();
momentBox.Text = moment.ToString();
sigmoidBetaBox.Text = sigmoidBeta.ToString();
errAppLimiteBox.Text = errAppLimite.ToString();
nbepoq.Text = nbrepoque.ToString();
}
est bien rattaché à l'evenement OnLoad de form1?? -
ben noir (windowtext)
-
franchement, je pense pas que cela soit ca...mais tu as quelle propiété de couleur pour l'affichage du text?? (dans textbox->forecolor??)
-
j'ai pas de msg d'erreurs, mais les valeurs ne s'affichent pas sur la Form
-
tu as quoi comme message d'erreur??
-
tu as bien rajouter:
pasAppBox.Text = pasApp.ToString();
momentBox.Text = moment.ToString(); ....etc a form1.cs* et ça a marcher, je comprends plus rien ou plutot si ça se trouve l erreur est insignifiante mais je vois pas ... -
Ca marche bien chez moi...
-
merci bien :) je vais essayer et te tenir au courant mais mais pour le Onload j ai deja essayer d ajouter l init des paramétres mais ça ne marche pas ...
a+ -
et pour tes event textChange tu peux les regrouper pour tous les textbox:
public partial class Form1 : Form { private double pasApp = 0.1; private double moment = 0.0; private double sigmoidBeta = 2.0; private double errAppLimite = 0.1; private int nbrepoque = 200; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { pasAppBox.Text = pasApp.ToString(); momentBox.Text = moment.ToString(); sigmoidBetaBox.Text = sigmoidBeta.ToString(); errAppLimiteBox.Text = errAppLimite.ToString(); nbepoq.Text = nbrepoque.ToString(); } private void button2_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { // pas apprentissage try { pasApp = Math.Max(0.00001, Math.Min(1, double.Parse(pasAppBox.Text))); } catch { pasApp = 0.1; } // le moment try { moment = Math.Max(0, Math.Min(0.5, double.Parse(momentBox.Text))); } catch { moment = 0; } // valeur de beta try { sigmoidBeta = Math.Max(0.01, Math.Min(100, double.Parse(sigmoidBetaBox.Text))); } catch { sigmoidBeta = 2; } // erreur apprentissage limite try { errAppLimite = Math.Max(0, double.Parse(errAppLimiteBox.Text)); } catch { errAppLimite = 0.1; } // nombre epoque try { nbrepoque = Math.Max(10, int.Parse(nbepoq.Text)); } catch { nbrepoque = 200; } } private void Text_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; if (txt.Text != null) { switch (txt.Name) { case "pasAppBox": pasApp = Convert.ToDouble(pasAppBox.Text); break; case "momentBox": moment = Convert.ToDouble(momentBox.Text); break; case "sigmoidBetaBox": sigmoidBeta = Convert.ToDouble(sigmoidBetaBox.Text); break; case "errAppLimiteBox": errAppLimite = Convert.ToDouble(errAppLimiteBox.Text); break; case "nbepoq": nbrepoque = Convert.ToInt32(nbepoq.Text); break; } } } }
J'espere ca pourra t'aider!!
@+ -
dans le OnLoad, effectivement rajoute l'init des parametres du type:
private void Form1_Load(object sender, EventArgs e)
{
pasAppBox.Text = pasApp.ToString();
momentBox.Text = moment.ToString();
}
ca devrait le faire....
-
Mais faudra que tu m'explique cela:
par exemple:
private void sigmoidBetaBox_TextChanged(object sender, EventArgs e)
{
sigmoidBetaBox.Text = sigmoidBeta.ToString();
}
je pense c'est plutot:
private void sigmoidBetaBox_TextChanged(object sender, EventArgs e)
{
if (sigmoidBetaBox.Text !=" ")
sigmoidBeta=Convert.ToDouble(sigmoidBetaBox.Text);
} -
voila ^^,
partial class Form1
{
/// <summary>
/// Variable nécessaire au concepteur.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Nettoyage des ressources utilisées.
/// </summary>
/// <param name="disposing">true si les ressources managées doivent être supprimées ; sinon, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Code généré par le Concepteur Windows Form
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.pasAppBox = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.sigmoidBetaBox = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.momentBox = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.errAppLimiteBox = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.nbepoq = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.label6 = new System.Windows.Forms.Label();
this.textBox6 = new System.Windows.Forms.TextBox();
this.label7 = new System.Windows.Forms.Label();
this.textBox7 = new System.Windows.Forms.TextBox();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.Location = new System.Drawing.Point(12, 25);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(105, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Pas d\'apprentissage:";
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// pasAppBox
//
this.pasAppBox.Location = new System.Drawing.Point(123, 26);
this.pasAppBox.Name = "pasAppBox";
this.pasAppBox.Size = new System.Drawing.Size(44, 20);
this.pasAppBox.TabIndex = 1;
this.pasAppBox.TextChanged += new System.EventHandler(this.pasAppBox_TextChanged);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 68);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(80, 13);
this.label2.TabIndex = 2;
this.label2.Text = "Valeur de Béta:";
//
// sigmoidBetaBox
//
this.sigmoidBetaBox.Location = new System.Drawing.Point(123, 61);
this.sigmoidBetaBox.Name = "sigmoidBetaBox";
this.sigmoidBetaBox.Size = new System.Drawing.Size(44, 20);
this.sigmoidBetaBox.TabIndex = 3;
this.sigmoidBetaBox.TextChanged += new System.EventHandler(this.sigmoidBetaBox_TextChanged);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 106);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(48, 13);
this.label3.TabIndex = 4;
this.label3.Text = "Moment:";
//
// momentBox
//
this.momentBox.Location = new System.Drawing.Point(123, 103);
this.momentBox.Name = "momentBox";
this.momentBox.Size = new System.Drawing.Size(44, 20);
this.momentBox.TabIndex = 5;
this.momentBox.TextChanged += new System.EventHandler(this.momentBox_TextChanged);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(12, 146);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(64, 13);
this.label4.TabIndex = 6;
this.label4.Text = "Erreur limite:";
//
// errAppLimiteBox
//
this.errAppLimiteBox.Location = new System.Drawing.Point(123, 143);
this.errAppLimiteBox.Name = "errAppLimiteBox";
this.errAppLimiteBox.Size = new System.Drawing.Size(44, 20);
this.errAppLimiteBox.TabIndex = 7;
this.errAppLimiteBox.TextChanged += new System.EventHandler(this.errAppLimiteBox_TextChanged);
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(12, 181);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(94, 13);
this.label5.TabIndex = 8;
this.label5.Text = "Nombre d\'époque:";
//
// nbepoq
//
this.nbepoq.Location = new System.Drawing.Point(123, 178);
this.nbepoq.Name = "nbepoq";
this.nbepoq.Size = new System.Drawing.Size(44, 20);
this.nbepoq.TabIndex = 9;
this.nbepoq.TextChanged += new System.EventHandler(this.nbepoq_TextChanged);
//
// button1
//
this.button1.Location = new System.Drawing.Point(15, 239);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 10;
this.button1.Text = "Démarrer";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(123, 239);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 11;
this.button2.Text = "Arréter";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// groupBox1
//
this.groupBox1.Location = new System.Drawing.Point(222, 25);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(299, 156);
this.groupBox1.TabIndex = 12;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "ErreurApprentissage";
//
// groupBox2
//
this.groupBox2.Location = new System.Drawing.Point(542, 25);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(299, 156);
this.groupBox2.TabIndex = 0;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "ErreurValidation";
//
// groupBox3
//
this.groupBox3.Location = new System.Drawing.Point(391, 239);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(299, 156);
this.groupBox3.TabIndex = 0;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "SortieDésirée/SortieApprentissage";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(12, 317);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(83, 13);
this.label6.TabIndex = 13;
this.label6.Text = "Erreur courante:";
//
// textBox6
//
this.textBox6.Location = new System.Drawing.Point(123, 310);
this.textBox6.Name = "textBox6";
this.textBox6.Size = new System.Drawing.Size(44, 20);
this.textBox6.TabIndex = 14;
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(12, 365);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(92, 13);
this.label7.TabIndex = 15;
this.label7.Text = "Epoque courante:";
//
// textBox7
//
this.textBox7.Location = new System.Drawing.Point(123, 365);
this.textBox7.Name = "textBox7";
this.textBox7.Size = new System.Drawing.Size(44, 20);
this.textBox7.TabIndex = 16;
//
// groupBox4
//
this.groupBox4.Location = new System.Drawing.Point(15, 423);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(200, 100);
this.groupBox4.TabIndex = 17;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "Informations";
//
// button3
//
this.button3.Location = new System.Drawing.Point(15, 562);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 0;
this.button3.Text = "Quitter";
this.button3.UseVisualStyleBackColor = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.ClientSize = new System.Drawing.Size(962, 610);
this.Controls.Add(this.button3);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.textBox7);
this.Controls.Add(this.label7);
this.Controls.Add(this.textBox6);
this.Controls.Add(this.label6);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.nbepoq);
this.Controls.Add(this.label5);
this.Controls.Add(this.errAppLimiteBox);
this.Controls.Add(this.label4);
this.Controls.Add(this.momentBox);
this.Controls.Add(this.label3);
this.Controls.Add(this.sigmoidBetaBox);
this.Controls.Add(this.label2);
this.Controls.Add(this.pasAppBox);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "RNA";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox pasAppBox;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox sigmoidBetaBox;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox momentBox;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox errAppLimiteBox;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox nbepoq;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox textBox6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.TextBox textBox7;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.Button button3;
}
} -
et le form1.designer.cs stp...car sinon, la form..je sais pas quelle trionche elle a!!;))
-
oui bien sur voila le code de form1.cs*
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
}
private double pasApp = 0.1;
private double moment = 0.0;
private double sigmoidBeta = 2.0;
private double errAppLimite = 0.1;
private int nbrepoque = 200;
private void button1_Click(object sender, EventArgs e)
{
// pas apprentissage
try
{
pasApp = Math.Max(0.00001, Math.Min(1, double.Parse(pasAppBox.Text)));
}
catch
{
pasApp = 0.1;
}
// le moment
try
{
moment = Math.Max(0, Math.Min(0.5, double.Parse(momentBox.Text)));
}
catch
{
moment = 0;
}
// valeur de beta
try
{
sigmoidBeta = Math.Max(0.01, Math.Min(100, double.Parse(sigmoidBetaBox.Text)));
}
catch
{
sigmoidBeta = 2;
}
// erreur apprentissage limite
try
{
errAppLimite = Math.Max(0, double.Parse(errAppLimiteBox.Text));
}
catch
{
errAppLimite = 0.1;
}
// nombre epoque
try
{
nbrepoque = Math.Max(10, int.Parse(nbepoq.Text));
}
catch
{
nbrepoque = 200;
}
}
private void pasAppBox_TextChanged(object sender, EventArgs e)
{
pasAppBox.Text = pasApp.ToString();
}
private void sigmoidBetaBox_TextChanged(object sender, EventArgs e)
{
sigmoidBetaBox.Text = sigmoidBeta.ToString();
}
private void momentBox_TextChanged(object sender, EventArgs e)
{
momentBox.Text = moment.ToString();
}
private void errAppLimiteBox_TextChanged(object sender, EventArgs e)
{
errAppLimiteBox.Text = errAppLimite.ToString();
}
private void nbepoq_TextChanged(object sender, EventArgs e)
{
nbepoq.Text = nbrepoque.ToString();
} -
Salut,
on peux voir tout le code.....
je pense que tu dois avoir une accolade en trop....car le code ne semble pas faux!!
@+ -
Bonjour,
non je l'ai pas appellée et quand je le fait, il me sort une erreur "updatesettings n existe pa dans le contexte actuel"+18 autres erreur lol!
- 1
- 2