Chinese (People's Republic of China)  English  Français


Supinfo-Projects.com
Supinfo Students' projects



Projects
  Last project
  Top projects
  All projects

74 User's online
3168 Projects


My Supinfo-Projects

   Login
   Create account


Synopsis

   6 Hits
   Visitors Score : 20
    (3 Voter)
   0 Comments

   Read the article

Evaluate this article

20
18
16
14
12
10
8
6
4
2
0


Comment this article

Author :

Email :

Your comment :



 
2006 - Pérennisation
Use and customize of host of forms of Visual Studio 2005 in your applications .net
[30 mn of reading - published 6/6/2006 8:37:04 PM - Target : Confirmé]

Author

wildarkWilliam GUIOUBLY
Student-Engineer Supinfo Paris
SUPINFO graduate year  2007

   Write to the person
   All projects of the same author
   Mini-CV of the author

5 The INameCreationService service

The INameCreationService service is an interface of the namespace System.ComponentModel.Design.Serialization. It provides methods to create a single name for the controls (To consult the MSDN to know all its methods, properties and events). One recovers this service via the GetService method of the DesignSurface class, while passing the System.ComponentModel.Design.Serialization.INameCreationService type in parameter. 

 

Let us examine somebody of these methods, properties and events:

- The CreateName method which permit to create a single name for the component of the originator.

- The IsValidName method indicates if not is single.

- The ValidateName method indicates if not is single, if it is not the case raises a exception.

 

There is no INameCreationService service by default in DesignSurface. We thus will create one of them to create a new NameCreationService class of it in our project which inherits System.ComponentModel.Design.Serialization.INameCreationService  as follows:

class NameCreationService : System.ComponentModel.Design.Serialization.

INameCreationService

{

    // Creation of a unique name for the control

    public string CreateName(System.ComponentModel.IContainer container, Type dataType)

    {

        int i = 0;

        string name = dataType.Name;

 

        while (true)

        {

            i++;

            // It is checked if the name is not used

            if (container.Components[name + i.ToString()] == null)

                break;

        }

 

        return name + i.ToString();

    }

 

    // Example drawn from the MSDN

    // If the name of the control contains a caracter different from miniature, of a masjucule, of a number return false

    public bool IsValidName(string name)

    {

        for (int i = 0; i < name.Length; i++)

        {

            char ch = name[i];

            UnicodeCategory uc = Char.GetUnicodeCategory(ch);

            switch (uc)

            {

                case UnicodeCategory.UppercaseLetter:

                case UnicodeCategory.LowercaseLetter:

                case UnicodeCategory.DecimalDigitNumber:

                    break;

                default:

                    return false;

            }

        }

        return true;    

    }

 

    // Example drawn from the MSDN

    // If the name of the control contains a caracter different from miniature, of a masjucule, of a number throw a exception

    public bool ValidateName(string name)

    {

        for (int i = 0; i < name.Length; i++)

        {

            char ch = name[i];

            UnicodeCategory uc = Char.GetUnicodeCategory(ch);

            switch (uc)

            {

                case UnicodeCategory.UppercaseLetter:

                case UnicodeCategory.LowercaseLetter:

                case UnicodeCategory.DecimalDigitNumber:

                    break;

                default:

                    throw new Exception("Le nom '" + name + "' n'est pas un identifiant valide.");

            }

        }  

    }

}

Now one will associate our NameCreationService class to our originator by modifying the code of the Designer class: 

public class Designer : System.ComponentModel.Design.DesignSurface

{

    public Designer()

    {

        // Service of creation of name

        ServiceContainer.AddService(

        typeof(System.ComponentModel.Design.Serialization.

        INameCreationService), new NameCreationService());

    }

}

 The ServiceContainer property of the DesignSurface class makes it possible to add and modify the list of the services associated with the originator.

 

To compile and launch the project and here what you obtain :

Exemple INameService.JPG

In the Name field of the propertyGrid, one can see that selected control has a single name well.



Articles de la même catégorie

 Pages : Top


5 Hits
0 Comments
ID3 and C4.5 algorithms
[40 mn of reading - published 6/6/2006 7:48:47 PM - Target : Confirmé]

More


9 Hits
0 Comments
Generics with .NET
[30 mn of reading - published 6/6/2006 3:37:29 PM - Target : Confirmé]

More


5 Hits
0 Comments
Widget Development
[10 mn of reading - published 6/6/2006 3:03:12 PM - Target : Débutant]

More

Powered by Campus-Booster Technology
Conditions d'utilisation & Copyright | Respect de la vie privée
© Copyright 1965-2006 Supinfo Paris, Paris Academy of Computer Science
Supinfo, Ecole Supérieure d'Informatique et Paris Academy Of Computer Science are trade marks.
23, rue de Château LANDON - 75010 PARIS - Phone : +33 (0) 153359 700 Fax : +33 (0) 153359 701

Web site autided by :