Windows 10 1803 x64 Build 17134.165, Visual Studio 2017 15.7.5 c#
我在表单上有一个自定义组合框。如果我构建针对任何CPU的解决方案,那没有问题,但是如果我将目标更改为x64,则在设计器中会出现此错误,并且组合框将从工具箱中删除。 designer.cs中的代码完整无缺,程序仍然可以正常运行。
Could not find type 'TestCustomComboBox.ComboBoxCustom'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built using settings for your current platform or Any CPU.
如果我恢复为Any CPU,则错误消失,并且组合框又回到了工具箱中。我的电脑是x64。
完整的测试程序:
using System.Drawing;
using System.Windows.Forms;
namespace TestCustomComboBox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
/// <summary>
/// Custom combobox with colour coding
/// </summary>
public class ComboBoxCustom : ComboBox
{
public ComboBoxCustom()
{
this.DrawMode = DrawMode.OwnerDrawFixed;
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
base.OnDrawItem(e);
e.DrawBackground();
var item = (ComboBoxItem)Items[e.Index];
Brush brush = new SolidBrush(item.ForeColor);
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{ brush = Brushes.Yellow; }
e.Graphics.DrawString(item.Text, this.Font, brush, e.Bounds.X, e.Bounds.Y);
}
}
public class ComboBoxItem
{
public ComboBoxItem() { }
public ComboBoxItem(string pText, object pValue)
{
text = pText; val = pValue;
}
public ComboBoxItem(string pText, object pValue, Color pColor)
{
text = pText; val = pValue; foreColor = pColor;
}
string text = "";
public string Text
{
get { return text; }
set { text = value; }
}
object val;
public object Value
{
get { return val; }
set { val = value; }
}
Color foreColor = Color.Black;
public Color ForeColor
{
get { return foreColor; }
set { foreColor = value; }
}
public override string ToString()
{
return text;
}
}
public class ComboObject
{
public string DisplayMembers;
public int ValueMembers;
public int argb;
public ComboObject(string theDisplayMembers, int theValueMembers, int theArgb)
{
DisplayMembers = theDisplayMembers;
ValueMembers = theValueMembers;
argb = theArgb;
}
public override string ToString()
{
return DisplayMembers;
}
}
}