Changing textBox from Method
-
I'm having trouble getting a textBox to accept a string from within a method. Start with:-
private static Form1 form = null; public Form1() { InitializeComponent(); form = this; } private void Form1\_Load(object sender, EventArgs e) { textBox2.Text = "Initialising....."; this.Show(); Refresh();
textBox2 shows up OK. However
form.UpDateText("Checking validity of " + FileName);
and
public void UpDateText(string ThisText) { using (StreamWriter logfile = new StreamWriter("D:\\\\TeklaZipping.log", true)) { logfile.WriteLine(ThisText); logfile.Close(); } Form1 frm1 = new Form1(); frm1.textBox1.Text += ThisText + System.Environment.NewLine; frm1.Refresh(); }
runs, and writes to logfile, but doesn't update textBox1. Any help appreciated.
ormonds
-
I'm having trouble getting a textBox to accept a string from within a method. Start with:-
private static Form1 form = null; public Form1() { InitializeComponent(); form = this; } private void Form1\_Load(object sender, EventArgs e) { textBox2.Text = "Initialising....."; this.Show(); Refresh();
textBox2 shows up OK. However
form.UpDateText("Checking validity of " + FileName);
and
public void UpDateText(string ThisText) { using (StreamWriter logfile = new StreamWriter("D:\\\\TeklaZipping.log", true)) { logfile.WriteLine(ThisText); logfile.Close(); } Form1 frm1 = new Form1(); frm1.textBox1.Text += ThisText + System.Environment.NewLine; frm1.Refresh(); }
runs, and writes to logfile, but doesn't update textBox1. Any help appreciated.
ormonds
It is updating textBox1 in a
new
instance offrm1
. Try something like below;//Form1 frm1 = new Form1(); this.textBox1.Text += ThisText + System.Environment.NewLine;
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
I'm having trouble getting a textBox to accept a string from within a method. Start with:-
private static Form1 form = null; public Form1() { InitializeComponent(); form = this; } private void Form1\_Load(object sender, EventArgs e) { textBox2.Text = "Initialising....."; this.Show(); Refresh();
textBox2 shows up OK. However
form.UpDateText("Checking validity of " + FileName);
and
public void UpDateText(string ThisText) { using (StreamWriter logfile = new StreamWriter("D:\\\\TeklaZipping.log", true)) { logfile.WriteLine(ThisText); logfile.Close(); } Form1 frm1 = new Form1(); frm1.textBox1.Text += ThisText + System.Environment.NewLine; frm1.Refresh(); }
runs, and writes to logfile, but doesn't update textBox1. Any help appreciated.
ormonds
ormonds wrote:
Form1 frm1 = new Form1();
This creates a new instance of Form1 and updates the textbox on the new instance. Remove the line and change
frm1.textbox1
tothis.textbox1
(this is not required but will help you to identify the source of the control).Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP
-
ormonds wrote:
Form1 frm1 = new Form1();
This creates a new instance of Form1 and updates the textbox on the new instance. Remove the line and change
frm1.textbox1
tothis.textbox1
(this is not required but will help you to identify the source of the control).Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP