.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Create textBox using Class in C#.net

Posted By:Narayanan       Posted Date: August 21, 2012    Points: 200    Category: C#    URL: http://www.dotnetspark.com  

In this Article, I will explain Create a TextBox in the Class file and call the method in any form in the Application.
 

you can create a Class in the Several ways in the .Net.
you can create via "Class.cs" file.
you can create via "CodeFile.cs" file.
you can create via "Form.cs" file.
Now , i will explain One by one .
you can create via "Class.cs" file:
Open your Project
Click "Project">> Add Class or Shift +Alt+C.
User can view the "Add New Item" window.
in the Name Input box , User can see the Class1.cs.
Click "OK" or change class file name in the input Box with Extension(.cs) and Clicks "Ok" button.
User can view this below format.

///Default namespaces
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Namespace_Program // Namespace Name
{
    class Class2 // Class name
    {
    }
}
Now , User add coding within the Class .
For Eg:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Namespace_Program
{
    class Class2  : Form  // We inherited form intoi class2
    {
       public static void TextBox(Form  frm)
        {
            TextBox txt = new TextBox();
            txt.Name = "txt_One";
            txt.Text = "Unit Testing";
            frm.Controls.Add(txt);
       }
    }
}
Now we just call this TextBox Method in the Form Class file
   Class2.TextBox(this);
Result: User can view the TextBox in the Form1 Designer at Run Time.
you can create via "CodeFile.cs" file:
we just create a method in the Class file using CodeFile.cs
using System;
using System.Windows.Forms;
namespace Test_namespace
{
    class dynamicControl : System.Windows.Forms.Form
    {
        public static void TextBox(Form frm)
        {
            TextBox txt = new TextBox();
            txt.Name = "txt_One";
            txt.Text = "Unit Testing";
            txt.Location = new System.Drawing.Point(20, 25);
            frm.Controls.Add(txt);
        }
    }
}
call in the Form.cs
 dynamicControl.TextBox(this);
you can create via "Form.cs" file:
open Form.cs
Copy and Paste code in the form.cs
  
 public static void TextBox(Form frm)
        {
            TextBox txt = new TextBox();
            txt.Name = "txt_One";
            txt.Text = "Testing";
            txt.Location = new Point(75, 100);
            frm.Controls.Add(txt);
        }

you can create via "Form.cs" file:
call the function in the form.cs
    TextBox(this);

I hope, this article helps you. Thanks for reading this Article.




 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend