在工具条按钮上导入按钮图像后 C# 项目构建错误
C# project build errors after importing button image on toolstrip button
我刚开始在 windows Form
.
上使用 ToolStrip
对象
我遵循了一个很好的教程,该教程解释了如何添加工具条,然后添加按钮,然后为按钮分配图像。
所以,我添加了工具条,然后添加了按钮:
如您所见,在上面的屏幕截图中,我还尝试了导入图像。我通过 right-clicking 按钮并选择 Set Image:
来完成此操作
当我点击确定时,这些额外的文件(MyGenioViewer1.Designer.cs)被自动生成:
但是现在项目无法编译。如果我恢复以前的备份并执行所有操作 除了 导入按钮,它会编译。
这些是错误:
Severity Code Description Project File Line Suppression State
Error CS0111 Type 'MyGenioView' already defines a member called '.ctor' with the same parameter types GENIO Viewer D:\My Programs\GENIO Viewer\GENIO Viewer\MyGenioView.cs 65 Active
Error CS0262 Partial declarations of 'MyGenioView' have conflicting accessibility modifiers GENIO Viewer D:\My Programs\GENIO Viewer\GENIO Viewer\MyGenioView.Designer.cs 25 Active
Error CS0260 Missing partial modifier on declaration of type 'MyGenioView'; another partial declaration of this type exists GENIO Viewer D:\My Programs\GENIO Viewer\GENIO Viewer\MyGenioView1.Designer.cs 25 Active
Error CS0111 Type 'MyGenioView' already defines a member called '.ctor' with the same parameter types GENIO Viewer D:\My Programs\GENIO Viewer\GENIO Viewer\MyGenioView1.Designer.cs 32 Active
Error CS0121 The call is ambiguous between the following methods or properties: 'MyGenioView.MyGenioView()' and 'MyGenioView.MyGenioView()' GENIO Viewer D:\My Programs\GENIO Viewer\GENIO Viewer\GENIO_Viewer_Form.cs 53 Active
很明显,这些额外文件的添加给我带来了麻烦。我不知道为什么要添加它们。我不知道如何解决这个问题。而且我不知道如何预防。
感谢您对正确解决此问题的任何说明。
原文MyGenioView.Designer.cs包含:
namespace GENIO_Viewer
{
partial class MyGenioView
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// MyGenioView
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Name = "MyGenioView";
this.ResumeLayout(false);
}
#endregion
}
}
导致问题的新 MyGenioView1.Designer.cs 是:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace GENIO_Viewer {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class MyGenioView {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal MyGenioView() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GENIO_Viewer.MyGenioView", typeof(MyGenioView).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}
你这里真是一团糟。不知何故,您最终得到了一个独立于表单的 Designer 文件。事实上,其中一个看起来根本不像设计师文件。我在您的屏幕截图中没有看到的是那些设计师应该链接到的表单。
它应该是这样的:
您没有显示此 class 的代码:MyGenioView.cs
,但我猜它至少已经定义了 MyGenioView1.Designer.cs
.[=14 中的一些内容=]
底线是你在太多地方有太多冲突(部分)classes。在我看来,您应该有一个 class(代码页)用于 MyGenioView
,另一个用于表单。其他任何事情都是矛盾的。
P.S。我还想知道您是否将 WPF 构造与 WinForms 混淆了。它们有很大的不同。你对 'View' 这个词的使用向我暗示了这一点。我可能是错的。
我刚开始在 windows Form
.
ToolStrip
对象
我遵循了一个很好的教程,该教程解释了如何添加工具条,然后添加按钮,然后为按钮分配图像。
所以,我添加了工具条,然后添加了按钮:
如您所见,在上面的屏幕截图中,我还尝试了导入图像。我通过 right-clicking 按钮并选择 Set Image:
来完成此操作当我点击确定时,这些额外的文件(MyGenioViewer1.Designer.cs)被自动生成:
但是现在项目无法编译。如果我恢复以前的备份并执行所有操作 除了 导入按钮,它会编译。
这些是错误:
Severity Code Description Project File Line Suppression State
Error CS0111 Type 'MyGenioView' already defines a member called '.ctor' with the same parameter types GENIO Viewer D:\My Programs\GENIO Viewer\GENIO Viewer\MyGenioView.cs 65 Active
Error CS0262 Partial declarations of 'MyGenioView' have conflicting accessibility modifiers GENIO Viewer D:\My Programs\GENIO Viewer\GENIO Viewer\MyGenioView.Designer.cs 25 Active
Error CS0260 Missing partial modifier on declaration of type 'MyGenioView'; another partial declaration of this type exists GENIO Viewer D:\My Programs\GENIO Viewer\GENIO Viewer\MyGenioView1.Designer.cs 25 Active
Error CS0111 Type 'MyGenioView' already defines a member called '.ctor' with the same parameter types GENIO Viewer D:\My Programs\GENIO Viewer\GENIO Viewer\MyGenioView1.Designer.cs 32 Active
Error CS0121 The call is ambiguous between the following methods or properties: 'MyGenioView.MyGenioView()' and 'MyGenioView.MyGenioView()' GENIO Viewer D:\My Programs\GENIO Viewer\GENIO Viewer\GENIO_Viewer_Form.cs 53 Active
很明显,这些额外文件的添加给我带来了麻烦。我不知道为什么要添加它们。我不知道如何解决这个问题。而且我不知道如何预防。
感谢您对正确解决此问题的任何说明。
原文MyGenioView.Designer.cs包含:
namespace GENIO_Viewer
{
partial class MyGenioView
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// MyGenioView
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Name = "MyGenioView";
this.ResumeLayout(false);
}
#endregion
}
}
导致问题的新 MyGenioView1.Designer.cs 是:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace GENIO_Viewer {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class MyGenioView {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal MyGenioView() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GENIO_Viewer.MyGenioView", typeof(MyGenioView).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}
你这里真是一团糟。不知何故,您最终得到了一个独立于表单的 Designer 文件。事实上,其中一个看起来根本不像设计师文件。我在您的屏幕截图中没有看到的是那些设计师应该链接到的表单。
它应该是这样的:
您没有显示此 class 的代码:MyGenioView.cs
,但我猜它至少已经定义了 MyGenioView1.Designer.cs
.[=14 中的一些内容=]
底线是你在太多地方有太多冲突(部分)classes。在我看来,您应该有一个 class(代码页)用于 MyGenioView
,另一个用于表单。其他任何事情都是矛盾的。
P.S。我还想知道您是否将 WPF 构造与 WinForms 混淆了。它们有很大的不同。你对 'View' 这个词的使用向我暗示了这一点。我可能是错的。