【发布时间】:2020-01-01 09:19:35
【问题描述】:
我正在编写一个 C# 表单应用程序。以下代码是我的“MainForm.cs”。
using CefSharp;
using CefSharp.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WinFormsChromium
{
public partial class MainForm : Form
{
public ChromiumWebBrowser browser;
public void InitBrowser()
{
Cef.Initialize(new CefSettings());
browser = new ChromiumWebBrowser("www.google.com");
this.Controls.Add(browser);
browser.Dock = DockStyle.Fill;
browser.LoadingStateChanged += browser_LoadingStateChanged;
}
private void browser_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
{
if (e.IsLoading == false)
{
browser.ExecuteScriptAsync("alert('All Resources Have Loaded');");
}
}
public MainForm()
{
InitializeComponent();
InitBrowser();
}
}
}
该文件没有问题。我的“MainForm.Designer.cs”有问题。下面的代码就是那个文件。
namespace Test
{
partial class MainForm
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.SuspendLayout();
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(534, 279);
this.Name = "MainForm";
this.Text = "Test";
this.ResumeLayout(false);
}
}
}
错误是“Test.MainForm.Dispose(bool): no suitable method to override (CS0115)”。我认为问题在于“受保护的覆盖无效处置(布尔处置)”。我该如何解决?
【问题讨论】:
-
你是否让组件继承了IDisposable?
-
@yaakov : 组件类需要是 IDisposable。
-
我该怎么做?
-
IContainer 是 also disposable,无论如何,如果不是,它会产生与 OP 不同的编译器错误。
-
当 foo.designer.cs 文件中的 Form 声明与 foo.cs 文件不同步时发生。在这种情况下,它是命名空间名称。您可以通过右键单击标识符名称并选择重命名来避免它。 IDE 足够聪明,可以随处更改。
标签: c#