#1: "A namespace does not directly contain members such as fields or methods" -- this is what it is. You did not put method in the form class, you messed up your curly brackets and put it outside the class but inside the name space.
#2: You can call the method of the class only if it is
static
, otherwise you can only call a method on instance to the class. You need to create an instance:
class MyClass {
internal MyAccessibleMethod() { }
public MyAccessibleMethodw() { }
int field;
}
MyClass myClassInstance = new MyClass();
myClassInstance.MyAccessibleMethod();
Of course, for accessibility the methods should be internal or public (if you need access from some other assembly).
Now, how instance methods work: pretty much like static methods, only there is an additional parameter called
this
. This parameter represents the instance, can be used to access instance members. It is not shown in parameter list but technically implemented as an extra hidden parameter. It is visible inside methods (including constructors):
internal MyAccessibleMethod() { this.field = 3; }
In most cases "
this.
" can be omitted. Sometimes, qualification of a member with "
this.
" is absolutely unavoidable. Example: there is a parameter with the same name as
field
.
#3: I just explained
this
; in your sample it can represent any instance of
Control
(including
Form
).
This code
btnAddClientInfo.Parent = this;
is equivalent to
this.Controls.Add(btnAddClientInfo);
This is a way to add children to a controls during run-time; can be done when a form is already shown -- the code will show a new child immediately. The child control should be set up before inserting (location, text, etc).
One general advice: stop doing Forms programming for a while: your level on confusion is too high. Instead, long the C# itself and some basic programming using much more simple coding, maybe as a console application.