views:

276

answers:

2

I have a 3rd party code library that I'm using; part of this library is a winforms application for editing the configuration files used by this library. I would like to embed their configuration editor app into my application.

I have the source code to their library and the configuration editor is (as far as I can tell) a straight forward Winforms app using standard controls. I'm trying to convert the app's main form into a UserControl so that I can host it inside my application which is WPF (WPF's WindowsFormsHost won't host a Form object, I get an exception).

I changed the form object to inherit from UserControl instead of Form and fixed all the compiler errors (there weren't many, just property initializations that don't exist on UserControls) but what's happening is my newly converted control is just blank.

When I run my test app I don't see any of the controls that make up the original form, just a blank page.

Any ideas? I really don't want to have to re-implement their app from scratch, that would suck.

Edit: I forgot to mention I'm testing this in a WinForms application, not WPF, to just get the control working before trying to use it from WPF.

+1  A: 

Clearly the InitializeComponent() method isn't running properly anymore. Not sure why of course.

Perhaps the better approach is to turn the form in a control:

  public partial class Form1 : Form {
    public Form1() {
      InitializeComponent();
      var f2 = new Form2();
      f2.TopLevel = false;
      f2.Location = new Point(5, 5);
      f2.FormBorderStyle = FormBorderStyle.None;
      f2.Visible = true;
      this.Controls.Add(f2);
    }
  }
Hans Passant
A: 

I have no idea why, but their InitializeComponent() method was basically setting all the controls Visible properties to False. I guess it must have used some form startup event to change them to visible that doesn't get called as a UserControl, setting their visibilities back to true fixed it.

Joe
When you initially opened up the form in your designer (before turning it into a user control) did you see all the controls?
MusiGenesis