c# - 在 VB6 中从 Form1 调用 Form2 使用实例问题
问题描述
实际上,我想在我的 VB6 项目中使用 cefsharp,但我遇到了以下两个问题:-
- 假设我的项目运行
form1
,我需要form2
使用 C# 类库调用我使用 cefsharp 初始化 chromium 浏览器的位置。
现在,当我从 form1 调用 form2 时
form2.showme
(这里showme
只是一个自定义函数来设置大小等),铬浏览器能够毫无问题地进行初始化,但是当我调用 form2 时
Public ofrm2 AS form2
Public Sub function()
Set ofrm2=new form2
call ofrm2.showme
End Sub
那么即使没有给出错误日志或任何类型的错误并且form2成功显示,但这次没有cefsharp chromium浏览器对象。
我也在使用SetParent
并SetWindowPos
在 form2 中设置我的铬浏览器的长度和宽度。我真的找不到问题,请提出一些解决方案。
- 第二个问题是,一旦我的代码初始化 chromium,VB6 编辑器就不允许调试。为我测试应用程序的唯一方法是制作一个exe,然后运行应用程序并尝试使用日志进行调试。
编辑:- *********************************************** *****************
我的 C# dll 包含 cefsharp 包
[PermissionSet(SecurityAction.Demand, Name ="FullTrust")]
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
[ClassInterface(ClassInterfaceType.None)]
public partial class Form1 : Form, IForm1
{
private ChromiumWebBrowser _browser;
public Form1()
{
InitializeComponent();
//initializeChromium();
}
public int initializeChromium()
{
CefSettings settings = new CefSettings();
if (!Cef.IsInitialized)
{
CefSharp.Cef.Initialize(settings);
}
_browser = new ChromiumWebBrowser("http://127.0.0.1:24125/ABC/DEF.html");
_browser.RegisterJsObject("External", this);
this.Controls.Add(_browser);
_browser.BringToFront();
_browser.Dock = DockStyle.Fill;
this.Show();
return 0;
}
}
我的表格1:-
Private Sub Form_Load()
Call launch ------ This one does not work. definition is given in my module below
'frmHTML.Show -----This one works
End Sub
Private Sub Form_UnLoad(cancel As Integer)
Set ofrmHtml = Nothing
End Sub
ModDec.bas:-
Option Explicit
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public ofrmHtml As frmHTML
Public Sub launch()
Set ofrmHtml = New frmHTML
Call ofrmHtml.InitChromium1
ofrmHtml.ShowMe
'call ofrmHtml.ShowMe
End Sub
我的 form2(frmHTML):-
Option Explicit
Public cSharpObj As New cSharp.Form1
Private Sub Form_Load()
'Call InitChromium1
Exit Sub
End Sub
Public Sub InitChromium1()
' On Error GoTo Err_Hndlr
SetParent cSharpObj.getHandle, frmHTML.hWnd
SetWindowPos cSharpObj.getHandle, 0, 0, 0, 512, 480, 0
Dim i As Integer
i = -1
i = cSharpObj.initializeChromium()
Exit Sub
End Sub
Public Sub ShowMe()
Call Me.Show
End Sub
解决方案
推荐阅读
- javascript - 在多个选项卡上打开同一个应用程序时服务人员的行为?
- mysql - 从 MYSQL 迁移到 Elasticsearch 的最佳方法是什么?
- android - 如何在 Google Pixel 3 中获取 Wi-Fi 信息?
- android - 如何控制 latLngBounds.southwest 和 latLngBounds.northeast 在多边形之外?
- s4sdk - 无法在 CF 中托管简单的 HelloWorld 应用程序或通过本地主机访问
- sql - 触发器未触发(编译成功)
- angular - 什么时候用Subject, BehaviorSubject 和实例
- ruby-on-rails - 如何检查传递给 `link_to` 的 url 是否有效
- phpstorm - 仅限 PhpStorm 大写 SQL 关键字
- vba - 奇怪的 VBA 演示文稿关闭运行时错误 #91