When you're working within a class's method, you can use "this" to refer to a member of the class. It's entirely optional, but considered good practice by many, since it makes it very explicit.
The only time it's required is if you have a local variable or argument to a method with the same name as a class variable, otherwise, it's optional:
class MyClass
{
private int number;
public void Foo()
{
number = 1; // this sets the class's private number variable, since there's no other "number" variable here...
}
public void RunCalculation(int number) // Note the same name used here as above
{
// .. do some work
// This will change the value of the argument passed in, but leave the number declared in the class alone
number = 3;
// this changes the class's private number variable directly
this.number = 4;
}
public void DoWork()
{
int number = 5; // this sets up a local variable, but leaves the class's variable alone
this.number = 2; // this sets the class's member explicitly
}
}
When you're working in a form, the designer sets up variables for you at the class (form) level. In your case, your text box is named "textBox3".
If you are in a method, and you do:
textBox3.Focus();
It finds that variable, because there isn't anything named that in the current scope. It will behave exactly the same as typing:
this.textBox3.Focus();
Reed Copsey, Jr. -
http://reedcopsey.com