Generating Objects with Code and Placing on the Form

Creating Objects in C#

C# is an object-oriented programming language. All the elements we use such as textbox, label, combobox, properties and ready methods of these elements are created by deriving from a class. Programmers can also create classes themselves and create objects and methods belonging to this class.

Objects that we create by dragging from the Toolbox onto the form are also derived from a class.

For example, when we create a TextBox by dragging it from the toolbox, Visual Studio performs the necessary operations for us and creates an object named TextBox1 from the TextBox class. 

When we put a lot of TextBoxes on the stage, we produce objects of the same class with different names and properties.

If we wish, we can also do object derivation with code.

Sample;

TextBox box1 = new TextBox();
box1.Text = "Hi";
box1.Left = 100;
box1.Ball = 50;
this.Controls.Add(box1);

If we examine the first line, it is stated in the left part of the equation that the object will derive from the TextBox class and its name will be box1.

The object is created in memory with the new command on the right of the equation and the constructor method of that class.

The object is now ready to use and its desired properties have been changed in the next 3 lines.

However, when the program runs, the object named box1 will still not appear. Adding the Textbox to the Form is done in the last line.

creating an object with c# code, creating textbox by code, label, object, adding code to the form

EXERCISES

There are no examples related to this subject.



COMMENTS




Read 605 times.

Online Users: 355



generating-objects-wiht-code-and-placing-on-form