Creating Help Links for Custom Controls using Verbs
Posted by dotnetinfo on September 10, 2008
.NET 2.0 provided an attribute to add to custom control. The Attribute used for the Help Link is Designer. The Designer is used in calendar control to create custom links. The idea can be used in multiple ways. The code explains an idea how to create help links on your custom controls.
Note: Code is not a complete code; the code provides an idea how to achieve the functionality. I might have renamed some objects to hide proprietary company names.
[Designer(typeof(CustomLabelDesigner))]
[HelpAttribute("http://internalsite.company.com/CustomLabel")]
public class CustomLabel : System.Web.UI.WebControls.Label
In CustomLabelDesigner.cs Inherited from ControlDesigner
public class CustomLabelDesigner: ControlDesigner
{
……………
…………..
………….
public override System.ComponentModel.Design.DesignerVerbCollection Verbs
{
get
{
DesignerVerbCollection v = new DesignerVerbCollection();
v.Add(new DesignerVerb(“Help link”, new EventHandler(HelpVerbHandler)));
return v;
}
}
private void HelpVerbHandler(object sender, System.EventArgs e)
{
// Creates a new form.
CustomLabel myLabel = new CustomLabel ();
// Gets the attributes for the collection.
System.ComponentModel.AttributeCollection attributes = TypeDescriptor.GetAttributes(myLabel);
//retrieve HelpAttribute
HelpAttribute attrib = (HelpAttribute)Attribute.GetCustomAttribute(typeof(CustomLabel), typeof(HelpAttribute));
//Display Data
System.Diagnostics.Process.Start(attrib.Url.ToString());
}
………………
Add a new HelpAttribute.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace SomeName.Company.Code
{
[AttributeUsage(AttributeTargets.Class)]
class HelpAttribute : System.Attribute
{
public readonly string Url;
public HelpAttribute(string url) // url is a positional parameter
{
this.Url = url;
}
}
}
Pictures :
