如何嵌入在C#的WinForms控制Java的控制? [英] How to embed a Java control on a C# winforms control?

查看:217
本文介绍了如何嵌入在C#的WinForms控制Java的控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以把Java控件(SWT,秋千,...)在C#控制?

Can I put a Java control (SWT, Swing, ...) on a C# control?

我知道这是可能的网络控制,但我不喜欢这种方式。

I know it's possible with web controls but I don't like this way.

推荐答案

我的复查,看起来像IKVM目前还没有足够的支持,在它的AFT组装。我认为,只有这样,才能做你需要运行你的java控制单独的进程里面有隐藏的主窗口,并通过该控件以某种方式您的C#应用​​程序的处理。

I've rechecked that, looks like IKVM currently hasn't enough support in it's AFT assembly. I think the only way to do what you need is run you java control inside separate process with hidden main window and pass handle of that control to your C# application somehow.

< HR />

原来的答复:

我不知道,如果你可以增加了,但你可以试试这个方向:

I'm not sure if you can just "add" it, but you can try this direction:

这将是必要的转换Java类.NET通过IKVM组件

It would be necessary to convert java classes to .Net assemblies via IKVM.


  1. 所有你需要获取Java控制手柄的第一。你可以看一下这个帖子如果您需要关于如何做到这一点的信息。我在这一步失败了,因为我还没有发现Win32DrawingSurface和DrawingSurfaces在IKVM的图书馆,也许是不够的,只是建立在Java端一些静态getHandle()方法。

  1. First of all you need to get handle of java control. You can look at this post if you need info on how to do this. I failed at this step because I haven't found Win32DrawingSurface and DrawingSurfaces in IKVM's libraries, maybe it's enough to just create some static getHandle() method on the java side.

让你的父母C#控件的句柄。这是简单,因为控制有其Handle属性。

Get handle of your parent C# control. It's simple since Control have its Handle property.

获得两个把手,您可以设置的一个作为父母到另一个之后。要做到这一点,你需要调用从WINAPI SetParent函数。

After obtaining both handles you can set one of the as parent to another. To do this you need to call SetParent function from the WINAPI.

函数[DllImport(user32.dll中)]
私人静态外部的IntPtr的setparent(IntPtr的hWndChild ,IntPtr的hWndNewParent);

[DllImport("user32.dll")] private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

这篇关于如何嵌入在C#的WinForms控制Java的控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆