Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Component Class

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 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