Solved

Component Class

Posted on 2013-10-30
3
184 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

21 Experts available now in Live!

Get 1:1 Help Now