Showing verbs in a PropertyGrid at runtime

I

Ian Ringrose

I wished to show verbs in a PropertyGrid that is hosted in my own WinForms
application. The normal way to show verbs is to provide a IDesigner
implementation, however this only works when the PropertyGrid is hosted
inside of MSDEV. This is my solution, comments please.

using System;
using System.ComponentModel;
using System.ComponentModel.Design;

namespace Main
{
/// <summary>
/// The class enables an object, to display 'verbs' in the property grid.
/// It should NOT be used for any object that will be edited with the
/// property grid that is in MSDEV. It is only usefull for property grids
that
/// are hosted in a customer WinForms app.
///
/// Override the Verbs::get method in sub classes to return the set of
verbs
/// for that class.
/// </summary>
[Serializable]
public class VerbHelper : IComponent, ISite, IMenuCommandService
{
public VerbHelper()
{
}

#region IComponent Members

public event System.EventHandler Disposed;

[Browsable(false)]
public ISite Site
{
get
{
return this;
}
set
{
throw new Exception("I hope this is never called!");
}
}

#endregion

#region ISite Members

[Browsable(false)]
public IComponent Component
{
get
{
return this;
}
}

[NonSerialized]
Container mContainer = null;
[Browsable(false)]
public IContainer Container
{
get
{
if (mContainer == null)
mContainer = new Container();

return mContainer;
}
}

[Browsable(false)]
public bool DesignMode
{
get
{
return false;
}
}


[Browsable(false)]
string ISite.Name
{
get
{
return "My Name";
}
set
{
}
}

#endregion

#region IServiceProvider Members

public object GetService(Type serviceType)
{
if (serviceType == typeof(IMenuCommandService))
return this;

return null;
}

#endregion

#region IDisposable Members

public void Dispose()
{
if (Disposed != null)
Disposed(this, EventArgs.Empty);
}

#endregion

#region IMenuCommandService Members

public void AddCommand(MenuCommand command)
{
}

public void RemoveVerb(DesignerVerb verb)
{
}

public void RemoveCommand(MenuCommand command)
{
}

public MenuCommand FindCommand(CommandID commandID)
{
return null;
}

public bool GlobalInvoke(CommandID commandID)
{
return false;
}

public void ShowContextMenu(CommandID menuID, int x, int y)
{
}

public void AddVerb(DesignerVerb verb)
{
}

[Browsable(false)]
virtual public DesignerVerbCollection Verbs
{
get
{
//override this in a sub class to return your verbs.
return new DesignerVerbCollection();
}
}

#endregion
}
}
 
G

Guest

Hello,

tried that cls, derived a Testclass, filled the DesignerVerbsCollection and assigned it to a Propertygrid within a Form - but no verbs anywhere ....anyone outthere who got it working ?
(ommitting the <Browsable(false)>-Attribute shows that there is a Verb in the collection ..but the PropertyGrid.canShowcomands is still false...and yes, .ShowCommandsIfAvailable is true)

guess i missed something ...

rolo
I wished to show verbs in a PropertyGrid that is hosted in my own WinForms
application. The normal way to show verbs is to provide a IDesigner
implementation, however this only works when the PropertyGrid is hosted
inside of MSDEV. This is my solution, comments please.

using System;
using System.ComponentModel;
using System.ComponentModel.Design;

namespace Main
{
/// <summary>
/// The class enables an object, to display 'verbs' in the property grid.
/// It should NOT be used for any object that will be edited with the
/// property grid that is in MSDEV. It is only usefull for property grids
that
/// are hosted in a customer WinForms app.
///
/// Override the Verbs::get method in sub classes to return the set of
verbs
/// for that class.
/// </summary>
[Serializable]
public class VerbHelper : IComponent, ISite, IMenuCommandService
{
public VerbHelper()
{
}

#region IComponent Members

public event System.EventHandler Disposed;

[Browsable(false)]
public ISite Site
{
get
{
return this;
}
set
{
throw new Exception("I hope this is never called!");
}
}

#endregion

#region ISite Members

[Browsable(false)]
public IComponent Component
{
get
{
return this;
}
}

[NonSerialized]
Container mContainer = null;
[Browsable(false)]
public IContainer Container
{
get
{
if (mContainer == null)
mContainer = new Container();

return mContainer;
}
}

[Browsable(false)]
public bool DesignMode
{
get
{
return false;
}
}


[Browsable(false)]
string ISite.Name
{
get
{
return "My Name";
}
set
{
}
}

#endregion

#region IServiceProvider Members

public object GetService(Type serviceType)
{
if (serviceType == typeof(IMenuCommandService))
return this;

return null;
}

#endregion

#region IDisposable Members

public void Dispose()
{
if (Disposed != null)
Disposed(this, EventArgs.Empty);
}

#endregion

#region IMenuCommandService Members

public void AddCommand(MenuCommand command)
{
}

public void RemoveVerb(DesignerVerb verb)
{
}

public void RemoveCommand(MenuCommand command)
{
}

public MenuCommand FindCommand(CommandID commandID)
{
return null;
}

public bool GlobalInvoke(CommandID commandID)
{
return false;
}

public void ShowContextMenu(CommandID menuID, int x, int y)
{
}

public void AddVerb(DesignerVerb verb)
{
}

[Browsable(false)]
virtual public DesignerVerbCollection Verbs
{
get
{
//override this in a sub class to return your verbs.
return new DesignerVerbCollection();
}
}

#endregion
}
}

User submitted from AEWNET (http://www.aewnet.com/)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top