Click here to Skip to main content
15,890,512 members
Home / Discussions / C#
   

C#

 
GeneralRe: MDI form with contents? Pin
Dave Kreskowiak21-Jan-11 10:29
mveDave Kreskowiak21-Jan-11 10:29 
AnswerRe: MDI form with contents? Pin
KarlRhodes24-Jan-11 6:22
KarlRhodes24-Jan-11 6:22 
QuestionCopying DropDownItems from one ToolStripDropDownItem to another Pin
Dewald21-Jan-11 2:24
Dewald21-Jan-11 2:24 
AnswerRe: Copying DropDownItems from one ToolStripDropDownItem to another Pin
musefan21-Jan-11 2:38
musefan21-Jan-11 2:38 
GeneralRe: Copying DropDownItems from one ToolStripDropDownItem to another Pin
Dewald21-Jan-11 3:10
Dewald21-Jan-11 3:10 
GeneralRe: Copying DropDownItems from one ToolStripDropDownItem to another Pin
musefan21-Jan-11 3:19
musefan21-Jan-11 3:19 
GeneralRe: Copying DropDownItems from one ToolStripDropDownItem to another Pin
musefan21-Jan-11 4:00
musefan21-Jan-11 4:00 
QuestionProblem to implement designer at runTime. Pin
hdv21221-Jan-11 2:15
hdv21221-Jan-11 2:15 
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
AnswerRe: Problem to implement designer at runTime. Pin
Richard MacCutchan21-Jan-11 2:52
mveRichard MacCutchan21-Jan-11 2:52 
GeneralRe: Problem to implement designer at runTime. Pin
hdv21221-Jan-11 5:32
hdv21221-Jan-11 5:32 
GeneralRe: Problem to implement designer at runTime. Pin
Richard MacCutchan21-Jan-11 6:28
mveRichard MacCutchan21-Jan-11 6:28 
GeneralRe: Problem to implement designer at runTime. Pin
hdv21222-Jan-11 5:23
hdv21222-Jan-11 5:23 
GeneralRe: Problem to implement designer at runTime. Pin
Richard MacCutchan22-Jan-11 6:37
mveRichard MacCutchan22-Jan-11 6:37 
AnswerRe: Problem to implement designer at runTime. Pin
Henry Minute21-Jan-11 4:17
Henry Minute21-Jan-11 4:17 
GeneralRe: Problem to implement designer at runTime. Pin
hdv21221-Jan-11 5:45
hdv21221-Jan-11 5:45 
GeneralRe: Problem to implement designer at runTime. Pin
Henry Minute21-Jan-11 5:56
Henry Minute21-Jan-11 5:56 
QuestionC# program to share screen using RDPCOMAPILIB.dll Pin
ayandelhi21-Jan-11 1:54
ayandelhi21-Jan-11 1:54 
AnswerRe: C# program to share screen using RDPCOMAPILIB.dll Pin
Bernhard Hiller21-Jan-11 3:43
Bernhard Hiller21-Jan-11 3:43 
AnswerRe: C# program to share screen using RDPCOMAPILIB.dll Pin
Nexuscan19-Jul-11 16:39
Nexuscan19-Jul-11 16:39 
Questionneed help in Basic Network programming in c# Pin
akosidandan20-Jan-11 17:16
akosidandan20-Jan-11 17:16 
AnswerRe: need help in Basic Network programming in c# Pin
Praveen Raghuvanshi20-Jan-11 18:36
professionalPraveen Raghuvanshi20-Jan-11 18:36 
QuestionHelp with file search Pin
turbosupramk320-Jan-11 11:56
turbosupramk320-Jan-11 11:56 
AnswerRe: Help with file search PinPopular
Luc Pattyn20-Jan-11 12:38
sitebuilderLuc Pattyn20-Jan-11 12:38 
GeneralRe: Help with file search Pin
turbosupramk320-Jan-11 13:12
turbosupramk320-Jan-11 13:12 
AnswerRe: Help with file search Pin
Luc Pattyn20-Jan-11 13:36
sitebuilderLuc Pattyn20-Jan-11 13:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.