M
M
Maxim K2021-06-28 23:07:42
C++ / C#
Maxim K, 2021-06-28 23:07:42

How to fix CefSharp (new tabs) error?

I make my browser (no bells and whistles), the only condition is to open links in a new tab.

I asked a question on the cefsharp general forum - they sent it to the link: , there are a lot of examples - I tried to compile, a lot of errors and other things. I went the other way: I found the source code of SharpBrowser - unpacked the bin folder, there is a fully working project and it has an implementation of opening a link in a new tab.

The file is called: ContextMenuHandlers.cs

private const int OpenLinkInNewTab = 26507;
......

      //Removing existing menu item
      //bool removed = model.Remove(CefMenuCommand.ViewSource); // Remove "View Source" option
      if (parameters.LinkUrl != "") {
        model.AddItem((CefMenuCommand)OpenLinkInNewTab, "Open link in new tab");
        model.AddItem((CefMenuCommand)CopyLinkAddress, "Copy link");
        model.AddSeparator();
      }

......

And the implementation in the method:

public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) {
if (id == OpenLinkInNewTab) {
        ChromiumWebBrowser newBrowser = myForm.AddNewBrowserTab(parameters.LinkUrl, false, browser.MainFrame.Url);
      }}

Added to myself, I get an error:

Severity	Code	Description	Project	File	Line	Suppression State
Error	CS1061	'Form1' does not contain a definition for 'AddNewBrowserTab' and no accessible extension method 'AddNewBrowserTab' accepting a first argument of type 'Form1' could be found (are you missing a using directive or an assembly reference?)	AGO	h:\РАЗЛИЧНЫЕ ПРОЕКТЫ\C#\MyCustomMenuHandler.cs	72	Active

What is AddNewBrowserTab? Added regular ControlTab, but didn't work. How to fix?

I will say that my project compiles completely and displays pages, i.e. even this code in the method above works:

// React to the first ID (show dev tools method)
            if (commandId == (CefMenuCommand)26501)
            {
                browser.GetHost().ShowDevTools();
                return true;
            }

I also found a folder with BrowserTabStrip in the sources - if this component needs to be used, how can I connect it to the project?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question