Setting Parent for a C# .NET Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all

I am new to C# and I need to be able to set the Parent to a window outside of C#. I want to embed a C# Form inside a Delphi Form. How can I set the Parent so that it uses the Handle from a Delphi Form

Help would be appreciated :

Kenneth
 
I would also like to know :)

Kenneth R. Lewis said:
Hello all,

I am new to C# and I need to be able to set the Parent to a window outside
of C#. I want to embed a C# Form inside a Delphi Form. How can I set the
Parent so that it uses the Handle from a Delphi Form?
 
Override the CreateParams property and specify the parent in the
CreateParams structure

/claes


Kenneth R. Lewis said:
Hello all,

I am new to C# and I need to be able to set the Parent to a window outside
of C#. I want to embed a C# Form inside a Delphi Form. How can I set the
Parent so that it uses the Handle from a Delphi Form?
 
* "=?Utf-8?B?S2VubmV0aCBSLiBMZXdpcw==?= said:
I am new to C# and I need to be able to set the Parent to a window
outside of C#. I want to embed a C# Form inside a Delphi Form. How can
I set the Parent so that it uses the Handle from a Delphi Form?

If you have both window handles:

\\\
[DllImport("USER32.DLL")]
private static extern IntPtr SetParent(
IntPtr hWndChild, // handle to window
IntPtr hWndNewParent // new parent window
);
///
 
I have achieved this by resorting to the good old windows API calls of
SetParent and in some case SetWindowLong... Its the whole parent - child and
owner - owned relationship issue that will govern which API call to use.

If you just want to show your form modally against the delphi form, you can
make use of the NativeWindow, set the handle of the delphi form in this
native window and then use ShowDialog(<your native window>) but to show
modeless forms, i don't think there is any alternative to using windows API.

HTH,

--Saurabh

Kenneth R. Lewis said:
Hello all,

I am new to C# and I need to be able to set the Parent to a window outside
of C#. I want to embed a C# Form inside a Delphi Form. How can I set the
Parent so that it uses the Handle from a Delphi Form?
 
Kenneth said:
Hello all,

I am new to C# and I need to be able to set the Parent to a window
outside of C#. I want to embed a C# Form inside a Delphi Form. How
can I set the Parent so that it uses the Handle from a Delphi Form?

Help would be appreciated :)

Kenneth

mmm, are you talking about a Delphi Win32 form ? (version 2-7) or a
Delphi 8 (for .net) form? and if Delphi 8 are you talking about a VCL
application or a WinForms application ?

I think the answer is in all cases you can't really do that.

a (System.Windows.Forms.Form) form is a top level control, and can't be
put into a containers Controls collection.

If you are looking at duplicating Frames type behaviour in Delphi, then
your best bet is to create a User Control, but this will only work for
Delphi 8 WinForms as a straight assembly or in a VCL app if you wrap
the user control in a Delphi package assembly.

Rgds Tim.
 
Back
Top