Search code examples
c#custom-controlscontrolsribbon

Cant cast custom control


I am attempting to use a Custom Ribbon panel, http://www.codeproject.com/Articles/25907/A-Professional-Ribbon-You-Will-Use-Now-with-orb, as well as working out a way to make a application that will take "Plugin" .dll's. This is the code that I am trying at the moment.

        Assembly assembly = Assembly.LoadFrom(@"dir");
        Type type = assembly.GetType("WindowsFormsControlLibrary2.UserControl1");
        object o = Activator.CreateInstance(type);
        string s = "GiveControl";
        UserControl uc = (UserControl)type.GetMethod(s).Invoke(o, null);
        ((Panel)uc.Controls.Find("panel1", true)[0]).Parent = panel2;

        RibbonTab rt = (RibbonTab)uc.Controls.Find("ribbonTab1", true)[0];

The last line is giving me an error that states "Cannot convert type 'System.Windows.Forms.Control' to 'System.Windows.Forms.RibbonTab'"

Its obvious what this message means, but I don't understand why it is happening. Is there a reason that custom controls can't be found this way?

This code/application is just a proof of concept/trying to find a way to do this (My first attempt). Any known ways to do this would be appreciated.

------UPDATE------
Appologies, I should have said, this error is happening at compile time, not at runtime.


Solution

  • This is because RibbonTab is not a control

    public class RibbonTab : Component, IRibbonElement, IContainsRibbonComponents