Bonjour,
J'ai créé une TextBox dans ma Form, et je cherche a récupérer sa valeur lors d'un clic sur un bouton pour pouvoir la sauvegarder ensuite. J'ai donc utilisé la propriété Text pour récupérer ce que l'utilisateur a entré mais problème : cette propriété est toujours vide.
Voici mon code :
Pour mon fichier Form1.cs
Pour mon fichier Form1.Designer.cs
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.Close(); string l_ToWrite = ""; l_ToWrite = DateTime.Now.ToString("dd/MM/yyyy;HH:mm:ss;") + textBox1.Text + Environment.NewLine; MessageBox.Show(l_ToWrite);
J'ai essayée de mettre la textBox1 en public mais cela ne changeait rien a mon problème.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 partial class Form2 { private void InitializeComponent() { this.textBox1 = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(26, 185); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(155, 20); this.textBox1.TabIndex = 4; // // button1 // this.button1.Location = new System.Drawing.Point(91, 226); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 7; this.button1.Text = "Send"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form2 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(271, 261); this.Controls.Add(this.button1); this.Controls.Add(this.textBox1); this.Name = "Form2"; this.Text = "questionnary"; this.ResumeLayout(false); this.PerformLayout(); } private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button button1;
Je ne vois pas vraiment ou est-ce-que j'aurais pu faire un erreur, quelqu'un aurait-il une idée ?
Merci par avance![]()
Partager