如何在C#winforms控件上嵌入Java控件?

时间:2022-09-02 12:31:50

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

我可以在C#控件上放置Java控件(SWT,Swing,...)吗?

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

我知道有可能使用网页控件,但我不喜欢这种方式。

5 个解决方案

#1


1  

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.

我已经重新检查过,看起来IKVM目前在它的AFT组件中没有足够的支持。我认为做你需要的唯一方法就是在隐藏主窗口的单独进程中运行java控件,并以某种方式将该控件的句柄传递给你的C#应用​​程序。


Original answer:

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

我不确定你是否可以“添加”它,但你可以尝试这个方向:

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

有必要通过IKVM将java类转换为.Net程序集。

  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.

    首先,你需要掌握java控件。如果您需要有关如何执行此操作的信息,可以查看此帖子。我在这一步失败了,因为我没有在IKVM的库中找到Win32DrawingSurface和DrawingSurfaces,也许只需在java端创建一些静态的getHandle()方法。

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

    获取父C#控件的句柄。这很简单,因为Control具有Handle属性。

  3. 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.

    获得两个句柄后,您可以将其中一个设置为另一个父项。为此,您需要从WINAPI调用SetParent函数。

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

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

#2


1  

I wrote examples:
- Java component embedding in .NET GUI,
- .NET WinForm Component embedding in Java GUI.
You can find them in the products:

http://www.simtel.net/product.php[id]95126[SiteID]simtel.net
http://www.simtel.net/product.php[id]98653[SiteID]simtel.net

我写了一些例子: - 在.NET GUI中嵌入Java组件, - 在Java GUI中嵌入.NET WinForm组件。您可以在以下产品中找到它们:http://www.simtel.net/product.php [id] 95126 [SiteID] ofim.net.net http://www.simtel.net/product.php[id]98653[SiteID ] simtel.net

#3


1  

You can use JNBridge to do it.

您可以使用JNBridge来执行此操作。

http://www.jnbridge.com/jnbp-examples.htm#JinN

#4


0  

Check out the IKVM project. Its a Java Virtual Machine implemented in .net which allows java and .net interoperability.

查看IKVM项目。它是一个在.net中实现的Java虚拟机,它允许java和.net互操作性。

Not sure exactly how complete it is and if it enables the functionality you require buts its worth a look.

不确定它究竟有多完整,是否能够实现您所需的功能,但值得一看。

#5


0  

If the control is not a custom control and is just something in swing you may find it available in Microsoft's Visual J# (either Version 2.0 or the supplemental add in for 1.1 http://msdn.microsoft.com/en-us/vjsharp/bb188695.aspx)

如果控件不是自定义控件而且只是摆动,你可能会发现它在Microsoft的Visual J#中可用(版本2.0或1.1的补充添加)http://msdn.microsoft.com/en-us/vjsharp/ bb188695.aspx)

Note that a J# Swing control will not play ball dropped in a WinForms app directly, you may need to provide a host control which delegates all painting to copying the image from a hidden J# Control placed within a simple j# Form (also hidden where the form's view area is resized to match the view area of the host control. This would at least remove the need for a separate process. This usage has several limitations, I suspect that the control you want to use is complex (or you would just have reimplemented it).

请注意,J#Swing控件不会直接在WinForms应用程序中播放球,您可能需要提供一个主机控件,该控件将所有绘图委托从一个隐藏的J#Control中复制图像,该控件放置在一个简单的j#Form中(也隐藏在表单的位置)视图区域被调整大小以匹配主机控件的视图区域。这至少可以消除对单独进程的需要。这种用法有一些限制,我怀疑你想要使用的控件很复杂(或者你只是重新实现了它)。

Note that J# is officially dying (no more serious maintenance) and will officially not bother to support it at all in 2015.Expect using it to cause you considerable pain in the long term but if you really need some part of it this might help.

请注意,J#正式死亡(没有更严重的维护),并且在2015年将完全支持它。在长期使用它会给你带来相当大的痛苦,但如果你真的需要它的一部分,这可能会有所帮助。

#1


1  

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.

我已经重新检查过,看起来IKVM目前在它的AFT组件中没有足够的支持。我认为做你需要的唯一方法就是在隐藏主窗口的单独进程中运行java控件,并以某种方式将该控件的句柄传递给你的C#应用​​程序。


Original answer:

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

我不确定你是否可以“添加”它,但你可以尝试这个方向:

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

有必要通过IKVM将java类转换为.Net程序集。

  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.

    首先,你需要掌握java控件。如果您需要有关如何执行此操作的信息,可以查看此帖子。我在这一步失败了,因为我没有在IKVM的库中找到Win32DrawingSurface和DrawingSurfaces,也许只需在java端创建一些静态的getHandle()方法。

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

    获取父C#控件的句柄。这很简单,因为Control具有Handle属性。

  3. 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.

    获得两个句柄后,您可以将其中一个设置为另一个父项。为此,您需要从WINAPI调用SetParent函数。

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

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

#2


1  

I wrote examples:
- Java component embedding in .NET GUI,
- .NET WinForm Component embedding in Java GUI.
You can find them in the products:

http://www.simtel.net/product.php[id]95126[SiteID]simtel.net
http://www.simtel.net/product.php[id]98653[SiteID]simtel.net

我写了一些例子: - 在.NET GUI中嵌入Java组件, - 在Java GUI中嵌入.NET WinForm组件。您可以在以下产品中找到它们:http://www.simtel.net/product.php [id] 95126 [SiteID] ofim.net.net http://www.simtel.net/product.php[id]98653[SiteID ] simtel.net

#3


1  

You can use JNBridge to do it.

您可以使用JNBridge来执行此操作。

http://www.jnbridge.com/jnbp-examples.htm#JinN

#4


0  

Check out the IKVM project. Its a Java Virtual Machine implemented in .net which allows java and .net interoperability.

查看IKVM项目。它是一个在.net中实现的Java虚拟机,它允许java和.net互操作性。

Not sure exactly how complete it is and if it enables the functionality you require buts its worth a look.

不确定它究竟有多完整,是否能够实现您所需的功能,但值得一看。

#5


0  

If the control is not a custom control and is just something in swing you may find it available in Microsoft's Visual J# (either Version 2.0 or the supplemental add in for 1.1 http://msdn.microsoft.com/en-us/vjsharp/bb188695.aspx)

如果控件不是自定义控件而且只是摆动,你可能会发现它在Microsoft的Visual J#中可用(版本2.0或1.1的补充添加)http://msdn.microsoft.com/en-us/vjsharp/ bb188695.aspx)

Note that a J# Swing control will not play ball dropped in a WinForms app directly, you may need to provide a host control which delegates all painting to copying the image from a hidden J# Control placed within a simple j# Form (also hidden where the form's view area is resized to match the view area of the host control. This would at least remove the need for a separate process. This usage has several limitations, I suspect that the control you want to use is complex (or you would just have reimplemented it).

请注意,J#Swing控件不会直接在WinForms应用程序中播放球,您可能需要提供一个主机控件,该控件将所有绘图委托从一个隐藏的J#Control中复制图像,该控件放置在一个简单的j#Form中(也隐藏在表单的位置)视图区域被调整大小以匹配主机控件的视图区域。这至少可以消除对单独进程的需要。这种用法有一些限制,我怀疑你想要使用的控件很复杂(或者你只是重新实现了它)。

Note that J# is officially dying (no more serious maintenance) and will officially not bother to support it at all in 2015.Expect using it to cause you considerable pain in the long term but if you really need some part of it this might help.

请注意,J#正式死亡(没有更严重的维护),并且在2015年将完全支持它。在长期使用它会给你带来相当大的痛苦,但如果你真的需要它的一部分,这可能会有所帮助。