我刚刚开始使用ToolStrip
上的Form
对象。
我遵循了一个很好的教程,解释了如何添加工具条,然后添加一个按钮,然后将图像分配给按钮。
所以,我添加了工具条,然后添加了按钮:
如您所见,在上面的屏幕截图中我也尝试导入图像。我通过右键单击按钮并选择设置图像:
来完成此操作单击“确定”后,会自动生成这些额外文件( 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;
}
}
}
}
答案 0 :(得分:1)
你这里真的很乱。不知何故,你最终得到了一个与Form不同的Designer文件。实际上,它根本不像设计师档案。我在屏幕截图中没有看到的是这些设计师应该链接的形式。
它应该是这样的:
您没有显示此课程的代码:MyGenioView.cs
,但我猜测它已经至少定义了MyGenioView1.Designer.cs
中的部分内容。
底线是你在太多地方有太多冲突(部分)类。在我看来,你应该为MyGenioView
提供一个类(代码页),为表单提供另一个类(代码页)。其他任何事都有冲突。
P.S。我也想知道你是否将WPF结构与WinForms混淆。他们是截然不同的。您使用&#39;查看&#39;向我建议这个。我可能错了。