0

I have been trying for days now to find a solution for my problem. I think the problem is simple but it won't work on my end and I'm not the best-experienced developer around the world. So Im using VB.net with CEFSharp and want to deactivate my browser to open links in new windows, I want that nothing happens then because I only have a web-based application which is included in Form1. So I already tried to translate some C# code:

 Public Class BrowserLifeSpanHandler
    Inherits ILifeSpanHandler

    Public Function OnBeforePopup(ByVal browserControl As IWebBrowser, ByVal browser As IBrowser, ByVal frame As IFrame, ByVal targetUrl As String, ByVal targetFrameName As String, ByVal targetDisposition As WindowOpenDisposition, ByVal userGesture As Boolean, ByVal popupFeatures As IPopupFeatures, ByVal windowInfo As IWindowInfo, ByVal browserSettings As IBrowserSettings, ByRef noJavascriptAccess As Boolean, <Out> ByRef newBrowser As IWebBrowser) As Boolean
        newBrowser = Nothing
        Return True
    End Function

But there are 2 errors. The first one is with the ILifeSpanHandler. It says that classes can only inherit from other classes. Was it wrong to put the code snippet over the End Class of my Form1? The second error is at <Out> ByRef newBrowser As IWebBrowser. Visual Studio says that type "Out" isnt defined. So what to put in there?

My main question: What do I have to change & why? :) Thanks.

Niklas H.
  • 1
  • 2
  • ILifeSpan is an Interface, not a class. So you either need BrowserLifeSpanHandler to be an interface that inherits ILifeSpanHandler, or BrowserLifeSpanHandler as a class must `Implement` ILifeSpanHandler. I think you want "Implements ILifeSpanHandler" – soohoonigan Dec 07 '17 at 20:06
  • Ok, I changed that. But then there are four other errors which say that class BrowserLifeSpanHandler has to implement Function OnBeforePopup, Sub OnAfterCreate, Function DoClose and Sub OnBeforeClose. So I pasted them all in but how do I fill in the arguments of those Functions and Sub? I mean for example Public Function OnBeforePopup(ByVal browserControl as IWebBrowser, ...) do I have to rename that to (ByVal MY_BROWSER_CONTROL_NAME as IWebBrowser, ...)? – Niklas H. Dec 07 '17 at 20:19
  • I'm sorry but I'm not quite sure what you mean. By implementing an interface, you have to have all the interface's methods available to be called because other classes/interfaces which were written to use ILifeSpanHandler assume that certain standard methods will be available. The arguments must be all the correct types and in the correct order, but the names of the arguments themselves don't matter. All that matters is that the method's signature matches, meaning its Name and argument types. i.e. MethodName(string, integer) or whatever – soohoonigan Dec 07 '17 at 20:37
  • OK. My source code is now the following but it still doesnt work there are for example no messageboxes shown. Source code: https://pastebin.com/ZFBpSyJm Because when I click on a link , there is a new window opened which I dont want. – Niklas H. Dec 08 '17 at 15:47
  • What can I do to fix that? There are no messageboxes which shows that I made a mistake - but I don't know what I made wrong... – Niklas H. Dec 08 '17 at 20:28

0 Answers0