Problem to implement designer at runTime.
-
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
-
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
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.
-
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
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!
-
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.
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[^]
-
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!
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[^]
-
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[^]
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!
-
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[^]
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.
-
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.