hi Justin,
Yeah, your first post to which i responded werent all that clear. Well for
a proper example of how microsoft is doing it you might want to look at
IEWebControls. They are supplying the source code along with it and they
have written two small class that do just that for the set of IEWebControls.
So why not rip that and use it, surely they wont mind
and surely nobody
could do it better than how they are doing it
They have created a custom
Editor. Its a set of two classes -- ObjectUrlEditor.cs and
ObjectImageUrlEditor.cs. The code is self explanatory and commented so you
shouldnt have a problem following and integrating it into your own control
//////////////////////////////////////////////////////////////////////Object
UrlEditor.cs//////////////////////////////////Start/////////////////////////
//////////////////////////////////////
namespace YourNameSpace
{
using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms.Design;
using System.Web.UI.Design;
using Microsoft.Web.UI.WebControls;
/// <summary>
/// Provides an editor for visually picking an URL.
/// </summary>
public class ObjectUrlEditor : UITypeEditor
{
/// <summary>
/// Gets the caption for the URL.
/// </summary>
protected virtual string Caption
{
get { return DesignUtil.GetStringResource("UrlCaption"); }
}
/// <summary>
/// Gets the filter to use.
/// </summary>
protected virtual string Filter
{
get { return DesignUtil.GetStringResource("UrlFilter"); }
}
/// <summary>
/// Gets the options for the URL picker.
/// </summary>
protected virtual UrlBuilderOptions Options
{
get { return UrlBuilderOptions.None; }
}
/// <summary>
/// Gets the editting style of the Edit method.
/// </summary>
/// <param name="context">The context</param>
/// <returns>The style</returns>
public override UITypeEditorEditStyle
GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
/// <summary>
/// Edits the specified object value using the editor style provided
by GetEditorStyle.
/// </summary>
/// <param name="context">Context</param>
/// <param name="provider">Provider</param>
/// <param name="value">The value to edit</param>
/// <returns>The editted value</returns>
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider, object value)
{
if (provider != null)
{
IWindowsFormsEditorService edSvc =
(IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorSe
rvice));
if (edSvc != null)
{
object node = null;
if (context.Instance is BaseChildNode)
{
node = context.Instance;
}
else if (context.Instance is object[])
{
object[] components = (object[])context.Instance;
if (components[0] is BaseChildNode)
{
node = components[0];
}
}
while ((node != null) && (node is BaseChildNode))
{
node = ((BaseChildNode)node).Parent;
}
if ((node != null) && (node is IComponent))
{
string url = UrlBuilder.BuildUrl((IComponent)node,
null, (string)value, Caption, Filter, Options);
if (url != null)
{
value = url;
}
}
}
}
return value;
}
}
}
////////////////////////////////////////////////////////////////////////////
/////////ObjectUrlEditor.cs//////////////////////////////////End////////////
////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////ObjectImageUrlEditor.cs///////////////////////////////////Start/////////
//////////////////////////////////////////
namespace YourNameSpace
{
/// <summary>
/// Provides an editor for visually picking an image URL.
/// </summary>
public class ObjectImageUrlEditor : ObjectUrlEditor
{
/// <summary>
/// Gets the caption for the URL.
/// </summary>
protected override string Caption
{
get { return DesignUtil.GetStringResource("ImageUrlCaption"); }
}
/// <summary>
/// Gets the filter to use.
/// </summary>
protected override string Filter
{
get { return DesignUtil.GetStringResource("ImageUrlFilter"); }
}
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////ObjectImageUrlEditor.cs/////////////////////
//////End//////////////////////////////////
//////////////////////////////////////////////////How to call the editor and
use it in your own
property////////////////////////////////////////////////////////////////////
/////////
////Now all you need to do is use the editor anywhere, when ever you need it
//////////////////////////////////////
/// <summary>
/// The URL of an image to display within the control.
/// </summary>
[
Category("Appearance"),
DefaultValue(""),
Editor(typeof(YourNameSpace.ObjectImageUrlEditor),
typeof(UITypeEditor)),
PersistenceMode(PersistenceMode.Attribute),
ResDescription("ItemImageUrl"),
]
public string ImageUrl
{
get
{
Object obj = ViewState["Image"];
return (obj == null) ? String.Empty : (string)obj;
}
set
{
ViewState["Image"] = value;
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////------//////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
Lemme know if it works or is what you want to do. I havent had the time to
test it or try it out yet
Alessandro