program.cs:
Код: Выделить всё
public class Program
{
[STAThread]
static void Main(string[] args)
{
var settings = new CefSettings
{
// Specify the same cache path for all instances
RootCachePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Cache"),
BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CustomBrowser.exe"),
};
Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: new CustomBrowserProcessHandler());
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Launch the main application form
Application.Run(new BrowserForm(args));
}
}
public class CustomBrowserProcessHandler : IBrowserProcessHandler
{
public bool OnAlreadyRunningAppRelaunch(IReadOnlyDictionary commandLine, string currentDirectory)
{
// This method is called in the first instance when a second instance is launched.
// Parse the command line for any arguments (e.g., URL to open)
if (Application.OpenForms.Count > 0)
{
var mainForm = Application.OpenForms[0];
var url = commandLine.ContainsKey("url") ? commandLine["url"] : "https://www.google.com";
/*
*
* if commandline contains "newprivatewindow" create a new private window.
* if commandline contains "newtab" create new tab in active window.
* if commandline contains "newwindow" create a new window.
*
*/
mainForm.Invoke((Action)(() =>
{
// Create a new browser form and show it
var newForm = new BrowserForm(new[] { url });
newForm.Show();
}));
return true; // Relaunch handled
}
return false; // Use default relaunch behavior
}
public void OnContextInitialized()
{
// Called after the CEF context has been initialized.
}
public void OnScheduleMessagePumpWork(long delay)
{
// Custom message pump work scheduling (optional).
}
public void Dispose()
{
throw new NotImplementedException();
}
}
Код: Выделить всё
public partial class BrowserForm : Form
{
private ChromiumWebBrowser browser;
public BrowserForm(string[] args)
{
InitializeComponent();
Text = "Custom Browser";
Width = 1024;
Height = 768;
// Parse command-line arguments for URL
var url = args.Length > 0 ? args[0] : "https://www.google.com";
browser = new ChromiumWebBrowser(url)
{
Dock = DockStyle.Fill
};
Controls.Add(browser);
// Add menu for opening new windows
var menuStrip = new MenuStrip();
var fileMenu = new ToolStripMenuItem("File");
var newWindowMenuItem = new ToolStripMenuItem("New Window", null, OpenNewWindow);
fileMenu.DropDownItems.Add(newWindowMenuItem);
menuStrip.Items.Add(fileMenu);
MainMenuStrip = menuStrip;
Controls.Add(menuStrip);
}
private void OpenNewWindow(object sender, EventArgs e)
{
// Open a new browser window
var newForm = new BrowserForm(new[] { "https://www.google.com" });
newForm.Show();
}
}
- перетаскивать При перетаскивании вкладки за пределы окон будет создано новое окно.
- перетаскивание вкладок из одного окна в другое.
Подробнее здесь: https://stackoverflow.com/questions/793 ... r-easytabs
Мобильная версия