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


Supinfo-Projects.com
Supinfo Students' projects



Projects
  Last project
  Top projects
  All projects

167 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

7 The IMenuCommandService service

The IMenuCommandService service is an interface of the namespace System.ComponentModel.Design. It provides methods for management of the menus and the verbs (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 type. IMenuCommandService  in parameter. 

 

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

- The Verbs property turns over the list of all the verbs associated the service.

- The AddCommand method adds a standard order to the service.

- The FindCommand method seeks a standard order starting from its id.  

- The GlobalInvoke method carries out a standard order. 

- The ShowContextMenu method posts a contextMenu. 

 

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

class MenuCommandService : System.ComponentModel.Design.IMenuCommandService

{

    // List of services od DesignSurface

    IServiceProvider serviceProvider;

    // Basic MenuCommmand

    System.ComponentModel.Design.MenuCommandService menuCommandService = null;

 

    public MenuCommandService(IServiceProvider serviceProvider)

    {

        this.serviceProvider = serviceProvider;

        menuCommandService = new System.ComponentModel.Design.MenuCommandService(serviceProvider);

    }

 

    // Show the contexteMenu

    // Show the command Delete

    public void ShowContextMenu(System.ComponentModel.Design.CommandID menuID, int x, int y)

    {

        // Creation of the contextMenu

        ContextMenu contextMenu = new ContextMenu();

 

        // Add the command Delete

        System.ComponentModel.Design.MenuCommand command = FindCommand(System.ComponentModel.Design.StandardCommands.Delete);

        if (command != null)

        {

            MenuItem menuItem = new MenuItem("Supprimer", new EventHandler(OnMenuClicked));

            menuItem.Tag = command;

            contextMenu.MenuItems.Add(menuItem);

        }

 

        // Select the service of view

        ViewService viewService = (ViewService)this.serviceProvider.GetService(typeof(ViewService));

        // Show the contexteMenu

        if (viewService.View != null)

        {

            contextMenu.Show(viewService.View, viewService.View.PointToClient(new Point(x, y)));

        }

    }

 

    // Management of the selections of the contexteMenu

    private void OnMenuClicked(object sender, EventArgs e)

    {

         MenuItem menuItem = sender as MenuItem;

        if (menuItem != null && menuItem.Tag is System.ComponentModel.Design.MenuCommand)

        {

            System.ComponentModel.Design.MenuCommand command = menuItem.Tag as System.ComponentModel.Design.MenuCommand;

            command.Invoke();

        }

    }

 

    // Add of standard command to the service

    public void AddCommand(System.ComponentModel.Design.MenuCommand command)

    {

        menuCommandService.AddCommand(command);

    }

 

    // Add the verb at the service

    public void AddVerb(System.ComponentModel.Design.DesignerVerb verb)

    {

         menuCommandService.AddVerb(verb);

    }

 

    // Search a standard command starting from its id

    public System.ComponentModel.Design.MenuCommand FindCommand(System.ComponentModel.Design.CommandID commandID)

    {

        return menuCommandService.FindCommand(commandID);

    }

 

    // Execute the standard command

    public bool GlobalInvoke(System.ComponentModel.Design.CommandID commandID)

    {

        return menuCommandService.GlobalInvoke(commandID);

    }

 

    // Remove a  standard command at the service

    public void RemoveCommand(System.ComponentModel.Design.MenuCommand command)

    {

        menuCommandService.RemoveCommand(command);

    }

 

    // Remove a verb from service

    public void RemoveVerb(System.ComponentModel.Design.DesignerVerb verb)

    {

        menuCommandService.RemoveVerb(verb);

    }

 

    // Obtain the list of verbs of the service

    public System.ComponentModel.Design.DesignerVerbCollection Verbs

    {

        get

        {

            return menuCommandService.Verbs;

        }

    }

}

 For the needs for the application, one will carry out a service which will contain the view of the form (It is this service which is used in the method ShowContextMenu  de  MenuCommandService):

class ViewService

{

    // View on the host

    private Control view = null;

 

    // Obtain or define the view of the host

    public Control View { get { return view; } set { view = value; } }

}

One will modify also the Designer class as follows:

class Designer : System.ComponentModel.Design.DesignSurface

{

    public Designer()

    {

        // Service of creation of name

        ServiceContainer.AddService(

typeof(System.ComponentModel.Design.Serialization.

INameCreationService), new NameCreationService());

 

        // Service of management of the toolbox

        ServiceContainer.AddService(

typeof(System.Drawing.Design.IToolboxService), new ToolBoxService());

 

        // Service of view of the host

        ServiceContainer.AddService(typeof(ViewService), new ViewService());

 

        // Service of management of the menus

        ServiceContainer.AddService(

typeof(System.ComponentModel.Design.IMenuCommandService), new MenuCommandService(this.ServiceContainer));

    }

}

As well as the Form1_Load event:

private void Form1_Load(object sender, EventArgs e)

{

   

 

    //Select and init the service of view

    ViewService viewService = (ViewService)designer.GetService(typeof(ViewService));

    //Inint the service

    viewService.View = (Control)designer.View;       

}

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

 

Exemple IMenuCommand.JPG

 

You can reveal a menu by the click right of the mouse and to remove the selected elements (except the control container).



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 :