Solved

Component Class

Posted on 2013-10-30
3
189 Views
Last Modified: 2013-10-31
Hi, I Just need to know the modifications needed in the following  code so that I can make this a "component " in order to drag and drop on a form.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BLLGeneric
{
    public class ValidateTitleClass
    {
        private static readonly ErrorProvider ErrorProvider = new ErrorProvider();

        public static void Validate(Control parent)
        {
            foreach (Control subcontrol in parent.Controls)
            {
                if (subcontrol is TextBox)
                {
                    var textbox = (TextBox) subcontrol;
                    var controltext = subcontrol.Name;
                    if (controltext == "Tbxdescription")
                    {
                        if (string.IsNullOrEmpty(textbox.Text))
                        {
                            ErrorProvider.SetError(subcontrol, "Field cannot be empty");
                        }
                    }
                    textbox.Text = null;
                }

                if (subcontrol.HasChildren)
                {
                    Validate(subcontrol);
                }
            }
        }

        public static object ClearErrorProvider()
        {
            ErrorProvider.Clear();
            ErrorProvider.Dispose();
            return null;
        }
    }
}

Open in new window

0
Comment
Question by:GRChandrashekar
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 39613026
Are you looking for this to be an Extender Provider?

Extender Providers
http://msdn.microsoft.com/en-us/library/ms171835(v=vs.110).aspx
0
 

Author Comment

by:GRChandrashekar
ID: 39613366
No I just want to change the code I have written to a component class not sure how can i do that
0
 
LVL 40
ID: 39613521
Inherit from Component in your class declaration:

public class ValidateTitleClass:System.ComponentModel.Component

Compile and the component will appear at the top of the Toolbox.

However, I do not see why you would make a component for a class that has only static methods. You gain nothing by doing so, since the methods in the class can be called at anytime in the application.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now