Newbie question
I am brand new to C# and to windows programming so please forgive me if this question is basic...I will learn (eventually).
I have developed a form for my user interface and I have written the basic logic for my program. How to I refer to (and change) a property of a label or other field on the form?
Thanks! Mike
AlanPosted Oct 15, 2008, 6:35 PM
Just follow the name of the control with the name of the property you want to access and separate them with a dot:
For example to change the Text property of label1:
label1.Text = "whatever";
and then to assign it to textBox1's Text property:
textBox1.Text = label1.Text;
If you like, you can precede the controls with the keyword 'this' which means it relates to the current instance of the form. Although code generated by Visual Studio's forms designer does this, it is usually unnecessary in code you write yourself:
this.textBox1.Text = this.label1.Text; // same effect as previous line
mikePosted Oct 15, 2008, 6:42 PM