Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unusual Events

Status
Not open for further replies.

Echilon

Programmer
Feb 22, 2007
54
GB
I'm trying to create an HTML editing control in C# using the technique at . The control works fine, but there's a nagging thing I'd like it to do.

Usually in a text editor, when you change the selection, if the selected text is bold or underlined, the bold/underline buttons appear selected in the toolbar. I need to update the buttons when the selection or caret position changes. I think I need to hook into the onselect method at , but I have no idea how to hook into an event of type "object". Is what I want possible?
 
object has no events. it only has Equals(object); GetHashCode(); and ToString();

you will need to determine what type of object it is and the process. you could do
Code:
if (obj.GetType() is typeof(a specific object))
{
  //do something with the specific object
}
else if(obj.GetType() is typeof(a different object))
{
}
else
{
}
but this gets messy real fast instead I would do something like this
Code:
class Exeucte
{
    private IEnumerable<IAction> actions

    public Execute(IEnumerable<IAction> actions)
    {
       this.actions = actions;
    }
    
    public void RequestOn(object subject)
    {
        foreach(IAction action in actions)
        {
            if(action.CanHandle(subject))
            {
               action.Handle(subject);
               break;
            }
        }
    }
}
have 1 action for each process. examples:
Code:
class BoldTextAction : IAction
{
   public bool CanHandel(object subject)
   {
   }
   public bool Handel(object subject)
   {
   }
}

class HyperLinkAction : IAction
{
   public bool CanHandel(object subject)
   {
   }
   public bool Handel(object subject)
   {
   }
}

class ChangeColorAction : IAction
{
   public bool CanHandel(object subject)
   {
   }
   public bool Handel(object subject)
   {
   }
}
a simple implementation would be
Code:
class DoSomeAction : IAction
{
   public bool CanHandel(object subject)
   {
      return subject as ISomeInterface != null;
   }
   public bool Handel(object subject)
   {
      ISomeInterface specificSubject = subject as ISomeInterface;
      if(specificSubject == null) return;

      specificSubject.DoSomething();
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top