如何解决在使用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 举报,一经查实,本站将立刻删除。