[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

IDE Component property editor options..

I've create a user control 'ConnectionPoint'

I then create a user control 'Connector', and give it two public ConnectionPoint properties for 'Source' and 'Target'

Drop one of each on a form, and look at the properties for 'Connector'. The 'Source' and 'Target' have drop-down lists which contain the 'ConnectionPoint1' instance I've added to the form.

Great.


Now I create a Box object, and give it two ConnectionPoint instances as properties.

Drop a Box object onto the form.

Is it possible to get the Connector's 'Source' property to include the connection points that exist within the box. For example, ideally I'd like the drop-down list to contain:

ConnectionPoint1 - the instance dropped directly ontot he form
Box1.ConnectionPoint1
Box1.ConnectionPoint2 - the two properties that are within the instance of Box, dropped on the form.


Obviously this doesn't happen automagically. Is there something I can do to make it so?

0
andrewjb
Asked:
andrewjb
1 Solution
 
Bob LearnedCommented:
You need to implement a TypeConverter.  

Here is an example, showing an extended Button user control and a TypeConverter:

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

public class SpecialButton : System.Windows.Forms.Button
{

  public SpecialButton()
  {
    this.Click += new EventHandler(ClickHandler);
    this.MouseMove += new MouseEventHandler(MouseMoveHandler);
    this.MouseLeave += new EventHandler(MouseLeaveHandler);
    this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
  }
  private string m_mouseMoveImage = string.Empty;

  [TypeConverter(typeof(EmbeddedImageTypeConverter))]
  public string MouseMoveImage
  {
    get
    {
      return m_mouseMoveImage;
    }
    set
    {
      if (m_mouseMoveImage != value)
      {
        m_mouseMoveImage = value;
      }
    }
  }
  private string m_clickImage = string.Empty;

  [TypeConverter(typeof(EmbeddedImageTypeConverter))]
  public string ClickImage
  {
    get
    {
      return m_clickImage;
    }
    set
    {
      if (m_clickImage != value)
      {
        m_clickImage = value;
      }
    }
  }

  private void ClickHandler(object sender, EventArgs e)
  {
    this.Image = new Bitmap(this.GetType(), this.ClickImage);
  }

  private void MouseMoveHandler(object sender, MouseEventArgs e)
  {
    this.Image = new Bitmap(this.GetType(), this.MouseMoveImage);
  }

  private void MouseLeaveHandler(object sender, EventArgs e)
  {
    this.Image = null;
  }
}

public class EmbeddedImageTypeConverter : TypeConverter
{

  public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context)
  {
    SortedList list = new SortedList();
    Assembly assy = Assembly.GetExecutingAssembly();
    string ns = this.GetType().Namespace;
    foreach (string name in assy.GetManifestResourceNames())
    {
      string extension = Path.GetExtension(name).ToLower();
      if (".bmp .gif .jpeg .png .tiff .wmf .emf".IndexOf(extension) != -1)
      {
        list.Add(name, name.Replace(ns + ".", string.Empty));
      }
    }
    return new StandardValuesCollection(list.Values);
  }

  public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
  {
    if (sourceType == typeof(string))
    {
      return true;
    }
    return false;
  }

  public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
  {
    if ((value == null))
    {
      return string.Empty;
    }
    if (value.GetType() != typeof(string))
    {
      throw base.GetConvertFromException(value);
    }
    return ((string)(value));
  }

  public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
  {
    return false;
  }

  public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
  {
    return true;
  }
}

Bob
0
 
andrewjbAuthor Commented:
OK. Thanks. Good start - pointed me in the right direction!
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now