How to make composite custom control and use it in windows Application

By
Composite control is very important functionality provided by the Microsoft.NET.Using custom control we can make windows forms application very easily. In Custom control application we can combine multiple controls according to our requirements.We can easily merge this custom control in any windows application.There are some advantage of composite custom control.
  • Less overhead on user
  • Maximum output
  • Less time consuming
  • It provides reusability like .dll file.
  • It is fast loading time.
Suppose if you want to make 100 or more application with similar functionality then you can make composite custom control for windows application.In this tutorial ,I am going to show "How to make composite custom control and use it in Windows forms Application".It provides more benifits if you are making more application with similar functionality.
There are some steps which are given below:-
Step 1:- First open your visual studio --> File -->New-->Project-->Select windows Forms control Library-->OK-->Now Drag and Drop Label,TextBox and Button control as shown below:-
login form

Step 2:- Now Double click on Login Button--> and write the following codes:-

using System;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsControlLibrary1
{
    public partial class customcontrol : UserControl
    {
        public delegate void del();
        public event del checkdetails;
        public string pid
        {
            set
            {
                textBox1.Text = value;
            }
            get
            {
                return textBox1.Text;
            }
        }
        public string password
        {
            set
            {
                textBox2.Text = value;
            }
            get
            {
                return textBox2.Text;
            }
        }
        public customcontrol()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" && textBox2.Text == "")
            {
                MessageBox.Show("please enter details");
            }
            else if (textBox1.Text == "")
            {
                MessageBox.Show("please enter id");
            }
            else if (textBox2.Text == "")
            {
                MessageBox.Show("please enter password");
            }
            else
            {
                if (checkdetails != null)
                {
                    checkdetails();
                }
                else
                {
                    MessageBox.Show("enter correct dtails");
                }
            }
        }
    }
}
Step 3:-Now Run the Application(press F5) --> and click on Load Button --> copy URL Path,which is as shown below:-


copy url

Step 4:- Now open your visual studio --> File--> New-->project-->Windows forms Application -->OK-->Now open Toolbox-->Right click on Toolbox -->click choose items as shown below:
choose items

Step 5:- Now click browse --> Paste the Url that you have copied before(otherwise Run First Application and get Url again)-->click on Arrow Button --> Select dll file as shown below-->Now click on  open Button.
select dll
Step 6:-Now open your Toolbox and Drag & Drop composite custom control on the Form as shown below:-
Toolbox

Step 7:- Now Double click on Form and write the following codes on the Form Load as given below.

using System;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
namespace composite_application
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            customcontrol1.checkdetails += new WindowsFormsControlLibrary1.customcontrol.del(customcontrol1_checkdetails);
        }

        void customcontrol1_checkdetails()
        {
            if (customcontrol1.pid == "user" && customcontrol1.password == "pass")
            {
          MessageBox.Show("welcome to http://msdotnet.co.in share it if possible");
            }
            else
            {
                MessageBox.Show("invalid user");
            }
        }
    }
}
Step 8:- Run the Application(press F5).There are some credentials which i have set in dll file which are given below:-

  • If you leave both Textbox field blank then it will give error"Please enter the password".
  • If you leave only password field  blank then then it will give error "please enter password".
  • If you leave only User Name Field blank then it will error "please enter the id".
  • If you fill both fill both Field correctly then it will give  Message "Welcome to http://msdotnet.co.in ,share it if possible". 
success

  • If you enter both field wrong then it will give error "Invalid user".
For More:-
  1. InterView Questions and Answers
  2. How to solve Sql server problems
  3. How add .mdf database on asp.net website
  4. Joins in Sql server
  5. How to add captcha control on the website
  6. Properties in c#
To Get the Latest  Free Updates Subscribe
For whole Application
         Download

0 comments:

Post a Comment

Powered by Blogger.