Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Creating user tabs or popup windows in Winforms

aimcosoftware edited this pageMay 23, 2023 ·1 revision

Implement your ownWinforms.LifeSpanHandler

When creating your own ChromiumWebBrowser instance, set the LifeSpanHandler to your own handler. You can use a global lifespan handler, rather than one for each browser.

DimHandlerInstanceAsNewMyLifeSpanHandler()DimMyBrowserAsNewChromiumWebBrowser()MyBrowser.LifeSpanHandler=HandlerInstance

HandlingOnBeforePopup in the LifespanHandler.

CEF will navigate the newBrowser and create a new renderer instance where needed. If the URL is on the the same site as the opener, it will use the same renderer.

ClassMyLifeSpanHandler:InheritsWinForms.Handler.LifeSpanHandlerProtectedOverridesFunctionOnBeforePopup(chromiumWebBrowserAsIWebBrowser,browserAsIBrowser,frameAsIFrame,targetUrlAsString,targetFrameNameAsString,targetDispositionAsWindowOpenDisposition,userGestureAsBoolean,popupFeaturesAsIPopupFeatures,windowInfoAsIWindowInfo,browserSettingsAsIBrowserSettings,ByRefnoJavascriptAccessAsBoolean,ByRefnewBrowserAsIWebBrowser)AsBoolean'Get Winforms control to create on same threadCType(chromiumWebBrowser,ChromiumWebBrowser).Invoke(Sub()'Create browser without URL and set as popupBrowser=NewChromiumWebBrowser()'Identify popup to use in DoCloseBrowser.Name="MyPopup"Browser.SetAsPopupBrowser.LifeSpanHandler=MeBrowser.Dock=DockStyle.Fill'This is a simple test, you can get better detail from targetDispositionIfpopupFeatures.IsPopupThen'Create your popup formDimFrm=NewMyPopupFrm'Will need to check zero, offscreen and minimum boundsFrm.Bounds=NewRectangle(popupFeatures.X,popupFeatures.Y,popupFeatures.Width,popupFeatures.Height)Frm.Controls.Add(Browser)'Need to show form on this threadFrm.Show()Else'Add browser to your tab controlDimTab=NewMyTabPageTab.Controls.Add(Browser)EndIfEndSub)'Pass back in newBrowser and set as childnewBrowser=BrowserwindowInfo.SetAsChild(newBrowser.Handle)'Return false (True cancels any popup)ReturnFalseEndFunction'Other functions in LifeSpanHandler...

HandlingDoClose request to close the popup

When a popup is closed by CEF e.g. from script, theDoClose() event is raised in theLifeSpanHandler.

'Function inside MyLifeSpanHandlerProtectedOverridesFunctionDoClose(WebBrowserAsIWebBrowser,browserAsIBrowser)AsBoolean'Get ChromiumWebBrowserDimBrowser=CType(WebBrowser,ChromiumWebBrowser)'Simple way to identify your popupIfBrowser.Name="MyPopup"Then'Close the parent form or tab from it's thread. (You may have to dispose related objects).Browser.BeginInvoke(Sub()Browser.Parent.Dispose())'Cancel default close message from CEFReturnTrueElse'Not our popup so allow close message from CEFReturnFalseEndIfEndFunction

Anyone with a GitHub account can edit this wiki, contributions are encouraged and welcomed.

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp