Delta Engine
»
Support
»
Engine
»
DeltaEngine render inside WinForms
Joined: 8/30/2013(UTC) Posts: 43
Thanks: 11 times Was thanked: 1 time(s) in 1 post(s)
|
Hi, is it possible to have render inside WinForms. E.g. in panel or some component? Thanks.
|
|
|
|
Joined: 5/15/2013(UTC) Posts: 45 Location: Hannover
Was thanked: 2 time(s) in 2 post(s)
|
Hi, I am informing my colleagues of this support request ;) |
|
|
|
|
Joined: 5/6/2013(UTC) Posts: 15
Was thanked: 2 time(s) in 2 post(s)
|
Originally Posted by: Matasx  Hi, is it possible to have render inside WinForms. E.g. in panel or some component? Thanks. Yes. We are doing it in the Editor. Since WPF is not able to do this, we are using a WindowsFormsHost within WPF to host the Rendering. Have a look at the WindowsFormsHost ViewportHost and its usages, as well as the WpfHostedFormsWindow
|
|
|
|
Joined: 8/30/2013(UTC) Posts: 43
Thanks: 11 times Was thanked: 1 time(s) in 1 post(s)
|
Ok, that sounds great.  But, I'm using pure old WinForms (no WPF) - is it somehow possible?
|
|
|
|
Medals:  Joined: 8/20/2011(UTC) Posts: 1,421 Location: Hannover
Thanks: 18 times Was thanked: 97 time(s) in 92 post(s)
|
Yes, very easy to do so. Every time you start an app on Windows it is rendered in a WinForms control, on WPF we use the WpfHostedFormsWindow as described by Steve.
Do you want us to provide a full sample how to use the FormsWindow as a panel in Forms window? If so please provide us with some code so we can guide you in the correct direction.
Basically you just derive from FormsWindow and use the FormsWindow(Control panel) constructor to set the panel you want to use for rendering. Then you create your Delta Engine App at initialization time in your Forms window via: new App(Window windowToRegister) (see WindowsOpenTK project or the Editor as an example)
|
|
|
|
Joined: 8/30/2013(UTC) Posts: 43
Thanks: 11 times Was thanked: 1 time(s) in 1 post(s)
|
Originally Posted by: Benjamin Nitschke  Basically you just derive from FormsWindow and use the FormsWindow(Control panel) constructor to set the panel you want to use for rendering. Then you create your Delta Engine App at initialization time in your Forms window via: new App(Window windowToRegister) (see WindowsOpenTK project or the Editor as an example) Thanks for your advice, but I need more hints. Quote:Basically you just derive from FormsWindow. What class should I derive from FormsWindow? My form must be derived from System.Windows.Forms.Form and C# does not support multiple inheritance.
|
|
|
|
Medals:  Joined: 8/20/2011(UTC) Posts: 1,421 Location: Hannover
Thanks: 18 times Was thanked: 97 time(s) in 92 post(s)
|
Just create a new class like the WpfHostedFormsWindow (which is derived from FormsWindow too, but not a WPF or WinForms thingy).
Then you create it inside your Forms window and use new App(window) and .Run to start the DE. If you could create a small application I can help better to inject the code at the right place. Then we can also include it as an example in the DE release.
|
|
|
|
Joined: 8/30/2013(UTC) Posts: 43
Thanks: 11 times Was thanked: 1 time(s) in 1 post(s)
|
Ok, here is what I'm trying to do (I know, I'm doing it wrong). Code: public partial class Form1 : Form
{
private PanelRender Delta;
public Form1()
{
InitializeComponent();
Delta = new PanelRender(panel1);
new App(); //v0.9.9.4 has no arguments and it is abstract class!
}
protected class PanelRender : FormsWindow
{
public PanelRender(Control panel) : base(panel)
{
}
}
}
|
|
|
|
Medals:  Joined: 8/20/2011(UTC) Posts: 1,421 Location: Hannover
Thanks: 18 times Was thanked: 97 time(s) in 92 post(s)
|
Here is an example for you (included in the next Delta Engine release also). It shows a line rendered with the Delta Engine on a plain Forms window: Code:
public partial class ExampleForm : Form
{
public ExampleForm()
{
InitializeComponent();
Show();
new RenderApp(new RenderPanel(panel1));
}
}
public class RenderPanel : FormsWindow
{
public RenderPanel(Control panel)
: base(panel)
{
}
}
public class RenderApp : App
{
public RenderApp(RenderPanel renderPanel)
: base(renderPanel)
{
new Line2D(Vector2D.Zero, Vector2D.One, Color.Yellow);
Run();
}
}
Screenshot and full source code + project files are attached. File Attachment(s):  WindowsFormsExample.zip (5kb) downloaded 2 time(s).Benjamin attached the following image(s):  WindowsFormsExample.png (4kb) downloaded 1 time(s).You cannot view/download attachments. Try to login or register.
|
 1 user thanked Benjamin for this useful post.
|
|
|
Joined: 8/30/2013(UTC) Posts: 43
Thanks: 11 times Was thanked: 1 time(s) in 1 post(s)
|
It is strange. App has no constructor with one parameter. Neither protected. Code:// Assembly DeltaEngine.WindowsSharpDX.dll, v0.9.9.4
using System;
namespace DeltaEngine.Platforms
{
public abstract class App
{
protected App();
protected T Resolve<T>() where T : class;
protected void Run();
}
}
|
|
|
|
Joined: 7/22/2013(UTC) Posts: 13
Thanks: 1 times Was thanked: 2 time(s) in 2 post(s)
|
Hi Matasx, you´re right. This implementation of the App-Class just exists in the OpenTK-DLL: Code:
/// <summary>
/// Initializes the OpenTK20Resolver and the window to get started. To execute the app call Run.
/// </summary>
public abstract class App
{
protected App() {}
internal App(Window windowToRegister)
{
resolver.RegisterInstance(windowToRegister);
}
private readonly OpenTK20Resolver resolver = new OpenTK20Resolver();
protected void Run()
{
resolver.Run();
}
protected internal T Resolve<T>() where T : class
{
return resolver.Resolve<T>();
}
}
}
Due to the internal-scope of the "RegisterInstance(windowToRegister)"-Method, you have to extend the original DeltaEngine.WindowsSharpDX assembly with your custom App-class (the code above) and add your DLL-reference to your project.
|
 1 user thanked ollimorp for this useful post.
|
|
|
Joined: 8/30/2013(UTC) Posts: 43
Thanks: 11 times Was thanked: 1 time(s) in 1 post(s)
|
Ok. With your help, I've managed to run it even under SharpDX. But, when I close main form, it throws an expcetion in program Main entry (Application.Run(new Form1()); or new Form1().ShowDialog(); - it doesn't matter) Code:System.ObjectDisposedException was unhandled
HResult=-2146232798
Message=K uvolněnému objektu nelze přistupovat. (=Cannot access to disposed object)
Název objektu: Form1
Source=System.Windows.Forms
ObjectName=Form1
StackTrace:
v System.Windows.Forms.Control.CreateHandle()
v System.Windows.Forms.Form.CreateHandle()
v System.Windows.Forms.Control.get_Handle()
v System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
v System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
v System.Windows.Forms.Application.RunDialog(Form form)
v System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
v System.Windows.Forms.Form.ShowDialog()
v DeltaExperiments.Program.Main() v ..\DeltaExperiments\Program.cs:řádek 41
v System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
v System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
v Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
v System.Threading.ThreadHelper.ThreadStart_Context(Object state)
v System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
v System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
v System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
v System.Threading.ThreadHelper.ThreadStart()
|
|
|
|
Medals:  Joined: 8/20/2011(UTC) Posts: 1,421 Location: Hannover
Thanks: 18 times Was thanked: 97 time(s) in 92 post(s)
|
I forgot to mention that we made that OpenTK App constructor public so it is easier to use it. We have only tested it with OpenTK, the other frameworks will also work, but are not tested well and might have more issues (like the one you mentioned via SharpDX).
In the next release you can find a more complete example in the Samples folder. In the meantime please modify the App.cs file in WindowsOpenTK yourself and let me know if you can get it all to work.
|
|
|
|
Delta Engine
»
Support
»
Engine
»
DeltaEngine render inside WinForms
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.