I just did a quick test in VB.NET, Visual Studio 2017 and it worked perfect, if I'm understanding your intention. Should work identical in C# targeting .NET Framework, but I dunno about Core, WPF or anything else. All I did was:
1. In my original browser app, add a new form ("Form2")
2. Change the form's FormBorderStyle to None
3. Put a panel in it ("panBrowser")
4. Set panel Dock to Fill.
5. Make a tiny code tweak in my original code, calling Form2 instead of the original Form1:
- Code: Select all
Imports CefSharp.WinForms
Imports CefSharp
Imports System.IO
Module CEFbrowser
Public WithEvents browser As ChromiumWebBrowser
Public CEFPath As String = ""
Dim settings As New CefSettings()
Sub LoadCEFBrowser()
CEFPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\MyBrowserTemp"
If Not Directory.Exists(CEFPath) Then
Try
Directory.CreateDirectory(CEFPath)
Catch ex As Exception
MsgBox("Error creating cache directory" + vbCrLf + CEFPath,, "Error")
End Try
End If
settings.CachePath = CEFPath
'CefSharpSettings.Proxy = new ProxyOptions(ip: "myipaddress", port: "myport", username: "myusername", password: "mypassword")
browser = New ChromiumWebBrowser("")
Dim requestContextSettings As New RequestContextSettings()
requestContextSettings.CachePath = CEFPath
requestContextSettings.PersistSessionCookies = True
browser.RequestContext = New RequestContext(requestContextSettings)
browser.Dock = DockStyle.Fill
If CefSharp.Cef.IsInitialized = False Then
CefSharp.Cef.Initialize(settings)
End If
Form2.panBrowser.Controls.Add(browser)
Form2.Show()
End Sub
Note that due to eliminating the title bar, you'll have to add extra mechanisms to allow the window to be moved etc.