Windows Form containing a Windows Form

  • Thread starter Thread starter Michael C#
  • Start date Start date
M

Michael C#

I have a Windows Form I want to add to another form similar to the way you
add an OpenFileDialog to a Windows Form from the Toolbox.

Thx
 
The OpenFileDialog is not a Windows Form, it is a Component that creates and
displays a form when a certain method is called. I suggest you read up on
creating controls and components. Those sections of the documentation should
have information on how to make a component appear in the toolbox.
 
Yeah, umm, thanx.

Now, back to business. Can anyone out there point me to some code samples
of how to create a component that creates a form? The tests I ran last
night had some issues including one in which the form tried to instantiate
itself during design time. Thank you.
 
I created a simple Control Library, added a component and a form. Added the
following code to the component:
public DialogResult ShowDialog(IWin32Window owner)
{
frmTest test = new frmTest();
return test.ShowDialog(owner);
}

Created an Application project, referenced the component, and added it to
the Application form, added a button, with the following Click Handler:
private void button1_Click(object sender, System.EventArgs e)
{
myComponent1.ShowDialog(this);
}

Works fine for me, and follows the same general pattern of OpenFileDialog.
It sounds to me like you're trying to create the form in the component
constructor. If that's what you really want to do, why don't you test
against Component.DesignMode?
 
Thank you! I think this will solve my problem. I was using an Inherited
form. It looks like I have to 1) declare the "test" Form variable outside
the ShowDialog function since I need the user to be able update the Form's
properties in some fashion and 2) I'm also going to have to declare a whole
new set of properties for the component that basically mirrors the Form's
properties, with some slight modifications (like using the Title property to
replace the Text property). That's actually the part I'm most hesitant
about... I was hoping there was a simpler way - in which I wouldn't have to
recreate all the Form's properties, etc.

Thanks
 
Back
Top