Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem to implement designer at runTime.

Problem to implement designer at runTime.

Scheduled Pinned Locked Moved C#
helpcomgraphicsdesigndata-structures
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hdv212
    wrote on last edited by
    #1

    Hi i want to implement deisgner at runTime in my app, to do this i 've create a simple win app and write this code to my form :

    public partial class Form1 : Form
    {
    IServiceContainer isc;
    DesignSurface ds;
    IDesignerHost idh;
    ISelectionService iss;
    IToolboxUser itu;
    MyToolBox toolbox;

    public Form1()
    {
    // Create the DesignSurface and load it with a form
    isc = new ServiceContainer();
    ds = new DesignSurface(isc);
    ds.BeginLoad(typeof(Form));

    idh = (IDesignerHost)ds.GetService(typeof(IDesignerHost));
    iss = (ISelectionService)ds.GetService(typeof(ISelectionService));
    itu = (IToolboxUser)idh.GetDesigner(idh.RootComponent);

    InitializeComponent();

    iss.SelectionChanged += new EventHandler(iss_SelectionChanged);
    }

    private void Form1_Load(object sender, EventArgs e)
    {
    toolbox = new MyToolBox();
    toolbox.Dock = DockStyle.Fill;
    splitContainer1.Panel1.Controls.Add(toolbox);
    isc.AddService(typeof(IToolboxService), toolbox);

    // Get the View of the DesignSurface, host it in a form, and show it
    Control c = ds.View as Control;
    c.Parent = this.splitContainer2.Panel1;
    c.Dock = DockStyle.Fill;
    }

    private void iss_SelectionChanged(object sender, EventArgs e)
    {
    propertyGrid1.SelectedObject = iss.PrimarySelection;
    }
    }

    and also create a new class named 'ToolboxServiceImp' which inherits from ListBox and IToolboxService as follow : Please download my sample app from http://cid-1490cc59dd735cbf.office.live.com/self.aspx/.Public/Designer2.rar my problem is that, at runTime when i drag & drop a control from my toolbox on the form, i got this error : Error --------------------------- Unable to cast object of type 'System.RuntimeType' to type 'System.Drawing.Design.ToolboxItem'. --------------------------- OK also, when i click on form, i got this error and designer become corrupt : Error --------------------------- The control System.Windows.Forms.Form has thrown an unhandled exception in the designer and has been disabled. Exception: Unable to cast object of type 'System.RuntimeType' to type 'System.Drawing.Design.ToolboxItem'. Stack trace: --------------------------- OK where is my problem and how to solve it ? thanks in advance

    L H 2 Replies Last reply
    0
    • H hdv212

      Hi i want to implement deisgner at runTime in my app, to do this i 've create a simple win app and write this code to my form :

      public partial class Form1 : Form
      {
      IServiceContainer isc;
      DesignSurface ds;
      IDesignerHost idh;
      ISelectionService iss;
      IToolboxUser itu;
      MyToolBox toolbox;

      public Form1()
      {
      // Create the DesignSurface and load it with a form
      isc = new ServiceContainer();
      ds = new DesignSurface(isc);
      ds.BeginLoad(typeof(Form));

      idh = (IDesignerHost)ds.GetService(typeof(IDesignerHost));
      iss = (ISelectionService)ds.GetService(typeof(ISelectionService));
      itu = (IToolboxUser)idh.GetDesigner(idh.RootComponent);

      InitializeComponent();

      iss.SelectionChanged += new EventHandler(iss_SelectionChanged);
      }

      private void Form1_Load(object sender, EventArgs e)
      {
      toolbox = new MyToolBox();
      toolbox.Dock = DockStyle.Fill;
      splitContainer1.Panel1.Controls.Add(toolbox);
      isc.AddService(typeof(IToolboxService), toolbox);

      // Get the View of the DesignSurface, host it in a form, and show it
      Control c = ds.View as Control;
      c.Parent = this.splitContainer2.Panel1;
      c.Dock = DockStyle.Fill;
      }

      private void iss_SelectionChanged(object sender, EventArgs e)
      {
      propertyGrid1.SelectedObject = iss.PrimarySelection;
      }
      }

      and also create a new class named 'ToolboxServiceImp' which inherits from ListBox and IToolboxService as follow : Please download my sample app from http://cid-1490cc59dd735cbf.office.live.com/self.aspx/.Public/Designer2.rar my problem is that, at runTime when i drag & drop a control from my toolbox on the form, i got this error : Error --------------------------- Unable to cast object of type 'System.RuntimeType' to type 'System.Drawing.Design.ToolboxItem'. --------------------------- OK also, when i click on form, i got this error and designer become corrupt : Error --------------------------- The control System.Windows.Forms.Form has thrown an unhandled exception in the designer and has been disabled. Exception: Unable to cast object of type 'System.RuntimeType' to type 'System.Drawing.Design.ToolboxItem'. Stack trace: --------------------------- OK where is my problem and how to solve it ? thanks in advance

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I don't plan to download your app, but I can guess that somewhere in your code you are trying to cast some object to a ToolboxItem, that does not have that class in its object hierarchy. You need to create the object of the correct type first.

      I must get a clever new signature for 2011.

      H 1 Reply Last reply
      0
      • H hdv212

        Hi i want to implement deisgner at runTime in my app, to do this i 've create a simple win app and write this code to my form :

        public partial class Form1 : Form
        {
        IServiceContainer isc;
        DesignSurface ds;
        IDesignerHost idh;
        ISelectionService iss;
        IToolboxUser itu;
        MyToolBox toolbox;

        public Form1()
        {
        // Create the DesignSurface and load it with a form
        isc = new ServiceContainer();
        ds = new DesignSurface(isc);
        ds.BeginLoad(typeof(Form));

        idh = (IDesignerHost)ds.GetService(typeof(IDesignerHost));
        iss = (ISelectionService)ds.GetService(typeof(ISelectionService));
        itu = (IToolboxUser)idh.GetDesigner(idh.RootComponent);

        InitializeComponent();

        iss.SelectionChanged += new EventHandler(iss_SelectionChanged);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        toolbox = new MyToolBox();
        toolbox.Dock = DockStyle.Fill;
        splitContainer1.Panel1.Controls.Add(toolbox);
        isc.AddService(typeof(IToolboxService), toolbox);

        // Get the View of the DesignSurface, host it in a form, and show it
        Control c = ds.View as Control;
        c.Parent = this.splitContainer2.Panel1;
        c.Dock = DockStyle.Fill;
        }

        private void iss_SelectionChanged(object sender, EventArgs e)
        {
        propertyGrid1.SelectedObject = iss.PrimarySelection;
        }
        }

        and also create a new class named 'ToolboxServiceImp' which inherits from ListBox and IToolboxService as follow : Please download my sample app from http://cid-1490cc59dd735cbf.office.live.com/self.aspx/.Public/Designer2.rar my problem is that, at runTime when i drag & drop a control from my toolbox on the form, i got this error : Error --------------------------- Unable to cast object of type 'System.RuntimeType' to type 'System.Drawing.Design.ToolboxItem'. --------------------------- OK also, when i click on form, i got this error and designer become corrupt : Error --------------------------- The control System.Windows.Forms.Form has thrown an unhandled exception in the designer and has been disabled. Exception: Unable to cast object of type 'System.RuntimeType' to type 'System.Drawing.Design.ToolboxItem'. Stack trace: --------------------------- OK where is my problem and how to solve it ? thanks in advance

        H Offline
        H Offline
        Henry Minute
        wrote on last edited by
        #3

        If you are interested in this sort of thing, you might want to look at the source for SharpDevelop[^] to see how they do it.

        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” I wouldn't let CG touch my Abacus!

        H 1 Reply Last reply
        0
        • L Lost User

          I don't plan to download your app, but I can guess that somewhere in your code you are trying to cast some object to a ToolboxItem, that does not have that class in its object hierarchy. You need to create the object of the correct type first.

          I must get a clever new signature for 2011.

          H Offline
          H Offline
          hdv212
          wrote on last edited by
          #4

          Hi do u have problem to download from this link ? http://cid-1490cc59dd735cbf.office.live.com/self.aspx/.Public/Designer2.rar[^] i found several example and source codes to demonstrate this, but all of them create a some new classes and write more complex code. here is some examples : http://msdn.microsoft.com/en-us/magazine/cc163634.aspx[^] Design Time Architecture in .NET 2.0 - Part 1[^]

          L 1 Reply Last reply
          0
          • H Henry Minute

            If you are interested in this sort of thing, you might want to look at the source for SharpDevelop[^] to see how they do it.

            Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” I wouldn't let CG touch my Abacus!

            H Offline
            H Offline
            hdv212
            wrote on last edited by
            #5

            Hi i found several example and source codes to demonstrate this, but all of them create a some new classes and write more complex code. here is some examples : http://msdn.microsoft.com/en-us/magazine/cc163634.aspx[^] Design Time Architecture in .NET 2.0 - Part 1[^]

            H 1 Reply Last reply
            0
            • H hdv212

              Hi i found several example and source codes to demonstrate this, but all of them create a some new classes and write more complex code. here is some examples : http://msdn.microsoft.com/en-us/magazine/cc163634.aspx[^] Design Time Architecture in .NET 2.0 - Part 1[^]

              H Offline
              H Offline
              Henry Minute
              wrote on last edited by
              #6

              hdv212 wrote:

              all of them create a some new classes and write more complex code.

              It is a complex topic. If you are looking for some simpler implementations, then maybe look at things like UML designers or Flow Chart designers. There are a fair few of those out there.

              Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” I wouldn't let CG touch my Abacus!

              1 Reply Last reply
              0
              • H hdv212

                Hi do u have problem to download from this link ? http://cid-1490cc59dd735cbf.office.live.com/self.aspx/.Public/Designer2.rar[^] i found several example and source codes to demonstrate this, but all of them create a some new classes and write more complex code. here is some examples : http://msdn.microsoft.com/en-us/magazine/cc163634.aspx[^] Design Time Architecture in .NET 2.0 - Part 1[^]

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                hdv212 wrote:

                do u have problem to download from this link ?

                Firstly, I do not download from external links. Secondly, I cannot unpack .rar files.

                hdv212 wrote:

                i found several example and source codes to demonstrate this, but all of them create a some new classes and write more complex code.

                I don't know what your experience level is, but mine is nowhere good enough to advise on the Microsoft sample.

                I must get a clever new signature for 2011.

                H 1 Reply Last reply
                0
                • L Lost User

                  hdv212 wrote:

                  do u have problem to download from this link ?

                  Firstly, I do not download from external links. Secondly, I cannot unpack .rar files.

                  hdv212 wrote:

                  i found several example and source codes to demonstrate this, but all of them create a some new classes and write more complex code.

                  I don't know what your experience level is, but mine is nowhere good enough to advise on the Microsoft sample.

                  I must get a clever new signature for 2011.

                  H Offline
                  H Offline
                  hdv212
                  wrote on last edited by
                  #8

                  Hi do u have problem to download my sample file ? do u have live account ?

                  L 1 Reply Last reply
                  0
                  • H hdv212

                    Hi do u have problem to download my sample file ? do u have live account ?

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    No to both questions. But as I said above, I don't have anything else to suggest to you.

                    I must get a clever new signature for 2011.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups