S
S
Sergey Kiselyov2022-04-16 02:32:27
C++ / C#
Sergey Kiselyov, 2022-04-16 02:32:27

How to merge 2 code snippets?

The script consists of several windows. In one of them, you need to embed a browser.

There is a form code snippet from visual studio:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;

namespace BUM
{
    public partial class Totalbattle : Form
    {
        public Totalbattle()
        {
            InitializeComponent();
        }

        private void totalbattle_formclosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            this.Hide();
        }
    }
}

You need to embed the second fragment (browser) into it:

namespace embebbedChromium
{
    public partial class Form1 : Form
    {
        public ChromiumWebBrowser chromeBrowser;
 
        public Form1()
        {
            InitializeComponent();
            // Start the browser after initialize global component
            InitializeChromium();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }

        public void InitializeChromium()
        {
            CefSettings settings = new CefSettings();
            // Initialize cef with the provided settings
            Cef.Initialize(settings);
            // Create a browser component
            chromeBrowser = new ChromiumWebBrowser("http://ourcodeworld.com");
            // Add it to the form and fill it to the form window.
            this.Controls.Add(chromeBrowser);
            chromeBrowser.Dock = DockStyle.Fill;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Cef.Shutdown();
        }        
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
forced, 2022-04-16
@forced

new Form().Show(parentId)
or ShowDialog

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question