在使用CefSharp Nuget包的CLR应用程序上获取鼠标单击坐标

如何解决在使用CefSharp Nuget包的CLR应用程序上获取鼠标单击坐标

我要获取用户在页面上单击的位置的坐标。基本上我希望在ChromiumWebBrowser页面上鼠标事件

我正在构建一个MFC MDI CView派生的浏览器应用程序,该应用程序使用对CLR的引用。为此,我点击了链接 https://www.youtube.com/watch?v=uBvDK6LE4XM

我正在使用nuget包cef.redist.x86(3.3325.1758),cef.redist.x64(3.3325.1758),CefSharp.Common(65.0.0-pre01),CefSharp.WinForms(65.0.0-pre01 )。

该实现有一个toolstripcontainer,我正在按以下方式加载浏览器:

ChromiumWebBrowser^ browser;
browser= gcnew ChromiumWebBrowser();
browser->Load("http://google.com");
this->CefToolStripContainer->ContentPanel->Controls->Add(browser);
browser->Dock = DockStyle::Fill;
this->AddressToolStripTextBox->Text = "http://google.com";

我能够获得OnFrameLoadEnd之类的事件。但是当我尝试获取鼠标事件时,执行此操作则什么也没发生

this->browser->Click += gcnew System::EventHandler(this,&clr_cefbrowser::CefBrowserCtrl::OnClick);

对于我添加的其他控件(从contentpanel中删除浏览器后)触发了click事件,但对浏览器不触发。 下面是实现的完整代码。

#pragma once

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

using namespace CefSharp;
using namespace CefSharp::WinForms;
using namespace System::Threading::Tasks;
using namespace System::Runtime::InteropServices;

#include <vector>


namespace clr_cefbrowser {

    /// <summary>
    /// Summary for CefBrowserCtrl
    /// </summary>
    public ref class CefBrowserCtrl : public System::Windows::Forms::UserControl
    {
    public:
        CefBrowserCtrl(void)
        {
            InitializeComponent();
            InitBrowser();
        }

    private:
        ChromiumWebBrowser^ browser;

    public:
        void InitBrowser()
        {
            browser = gcnew ChromiumWebBrowser();
            browser->Load("http://google.com");
            this->CefToolStripContainer->ContentPanel
                ->Controls->Add(browser);
            browser->Dock = DockStyle::Fill;
            this->AddressToolStripTextBox->Text = "http://google.com";
            this->browser->Click += gcnew System::EventHandler(this,&clr_cefbrowser::CefBrowserCtrl::OnClick);
        }

    protected:
        ~CefBrowserCtrl()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::ToolStripContainer^  CefToolStripContainer;
    private: System::Windows::Forms::ToolStrip^  CefToolStrip;
    private: System::Windows::Forms::ToolStripLabel^  toolStripLabel1;
    private: System::Windows::Forms::ToolStripTextBox^  AddressToolStripTextBox;
    private: System::Windows::Forms::ToolStripButton^  GoToolStripButton;
    protected:

    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container ^components;

   #pragma region Windows Form Designer generated code
   void InitializeComponent(void)
   {
      System::ComponentModel::ComponentResourceManager^  resources = (gcnew 
      System::ComponentModel::ComponentResourceManager(CefBrowserCtrl::typeid));
      this->CefToolStripContainer = (gcnew System::Windows::Forms::ToolStripContainer());
      this->CefToolStrip = (gcnew System::Windows::Forms::ToolStrip());
      this->toolStripLabel1 = (gcnew System::Windows::Forms::ToolStripLabel());
      this->AddressToolStripTextBox = (gcnew System::Windows::Forms::ToolStripTextBox());
      this->GoToolStripButton = (gcnew System::Windows::Forms::ToolStripButton());
      this->CefToolStripContainer->TopToolStripPanel->SuspendLayout();
      this->CefToolStripContainer->SuspendLayout();
      this->CefToolStrip->SuspendLayout();
      this->SuspendLayout();
      // 
      // CefToolStripContainer
      // 
      // 
      // CefToolStripContainer.ContentPanel
      // 
      this->CefToolStripContainer->ContentPanel->Size = System::Drawing::Size(476,265);
      this->CefToolStripContainer->Dock = System::Windows::Forms::DockStyle::Fill;
      this->CefToolStripContainer->Location = System::Drawing::Point(0,0);
      this->CefToolStripContainer->Name = L"CefToolStripContainer";
      this->CefToolStripContainer->Size = System::Drawing::Size(476,290);
      this->CefToolStripContainer->TabIndex = 0;
      this->CefToolStripContainer->Text = L"toolStripContainer1";
      // 
      // CefToolStripContainer.TopToolStripPanel
      // 
      this->CefToolStripContainer->TopToolStripPanel->Controls->Add(this->CefToolStrip);
     // 
     // CefToolStrip
     // 
     this->CefToolStrip->Dock = System::Windows::Forms::DockStyle::None;
     this->CefToolStrip->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(3) {
    this->toolStripLabel1,this->AddressToolStripTextBox,this->GoToolStripButton
    });
    this->CefToolStrip->Location = System::Drawing::Point(3,0);
    this->CefToolStrip->Name = L"CefToolStrip";
    this->CefToolStrip->Size = System::Drawing::Size(337,25);
    this->CefToolStrip->TabIndex = 0;
    // 
    // toolStripLabel1
    // 
    this->toolStripLabel1->Name = L"toolStripLabel1";
    this->toolStripLabel1->Size = System::Drawing::Size(31,22);
    this->toolStripLabel1->Text = L"URL:";
    // 
    // AddressToolStripTextBox
    // 
    this->AddressToolStripTextBox->Name = L"AddressToolStripTextBox";
    this->AddressToolStripTextBox->Size = System::Drawing::Size(250,25);
    // 
    // GoToolStripButton
    // 
    this->GoToolStripButton->Image = (cli::safe_cast<System::Drawing::Image^>(resources- 
    >GetObject(L"GoToolStripButton.Image")));
    this->GoToolStripButton->ImageTransparentColor = System::Drawing::Color::Magenta;
    this->GoToolStripButton->Name = L"GoToolStripButton";
    this->GoToolStripButton->Size = System::Drawing::Size(42,22);
    this->GoToolStripButton->Text = L"Go";
    this->GoToolStripButton->Click += gcnew System::EventHandler(this,&CefBrowserCtrl::GoToolStripButton_Click);
    // 
    // CefBrowserCtrl
    // 
    this->AutoScaleDimensions = System::Drawing::SizeF(7,12);
    this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    this->Controls->Add(this->CefToolStripContainer);
    this->DoubleBuffered = true;
    this->Name = L"CefBrowserCtrl";
    this->Size = System::Drawing::Size(476,290);
    this->CefToolStripContainer->TopToolStripPanel->ResumeLayout(false);
    this->CefToolStripContainer->TopToolStripPanel->PerformLayout();
    this->CefToolStripContainer->ResumeLayout(false);
    this->CefToolStripContainer->PerformLayout();
    this->CefToolStrip->ResumeLayout(false);
    this->CefToolStrip->PerformLayout();
    this->ResumeLayout(false);

}

#pragma endregion
  public:
    ClrChromiumWebBrowser^ GetBrowser()
    {
        return this->browser;
    }
    
  private:          
    void OnClick(System::Object ^sender,System::EventArgs ^e);

}; }

void clr_cefbrowser::CefBrowserCtrl::OnClick(System::Object ^sender,System::EventArgs ^e)
{
    MessageBox::Show("Click Event");
}

在“我的视图”课程中,我有

CWinFormsControl<clr_cefbrowser::CefBrowserCtrl> m_CefBrowser;

然后我使用BEGIN_DELEGATE_MAP和MAKE_DELEGATE得到frameloadend事件。 我真的不确定如何从这里继续。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-