Ich habe ein benutzerdefiniertes Steuerelement mit einer allgemeinen Liste von benutzerdefinierten Typen. Diese Liste ist öffentlich definiert:C# Winforms Visual Studio-Designer kann benutzerdefinierten Typ nicht finden
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Editor(typeof(ButtonPanelXEditor), typeof(UITypeEditor))]
public List<CompactButton> CompactButtons
{
get { return _compactButtons; }
set { _compactButtons = value; }
}
Als ich dieses Steuerelement zu meiner Form hinzufügen und bauen mein Projekt, das ich diesen Fehler:
Error 1 Could not find a type for a name. The type name was 'ButtonPanelX.CompactButton, ButtonPanelX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Line 127, position 5. D:\Projecten\ButtonPanelX\ButtonPanelX\Form1.resx 127 5 ButtonPanelX
Wenn ich Strings statt benutzerdefinierte Objekte verwenden, wird die desginer sparen meine Liste. CompactButton
hat das Attribut [Serializable]
und leitet sich von ISerializable
Was kann ich tun, um das zu beheben?
Edit:
public class ButtonPanelXEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
if (context != null && context.Instance != null)
// We will use a window for property editing.
return UITypeEditorEditStyle.Modal;
return base.GetEditStyle(context);
}
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context,
IServiceProvider provider, object value)
{
context.OnComponentChanging();
ButtonPanel b = context.Instance as ButtonPanel;
FooBar form = new FooBar();
form.Buttons = b.CompactButtons;
form.ShowDialog();
b.CompactButtons = form.Buttons;
b.DrawButtons();
context.OnComponentChanged();
return form.Buttons;
}
}
EDIT 2:
[Serializable]
public partial class ButtonPanel : UserControl
{
private ArrayList _compactButtons;
public ButtonPanel()
{
InitializeComponent();
_compactButtons = new ArrayList();
AddButtons();
this.Load += new EventHandler(ButtonPanel_Load);
}
void ButtonPanel_Load(object sender, EventArgs e)
{
DrawButtons();
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Editor(typeof(ButtonPanelXEditor), typeof(UITypeEditor))]
public ArrayList CompactButtons
{
get { return _compactButtons; }
}
public void DrawButtons()
{
baseButton1.Visible = ((CompactButton)_compactButtons[0]).Visible;
baseButton2.Visible = ((CompactButton)_compactButtons[1]).Visible;
}
private void AddButtons()
{
/* Buttons baseButton1 and baseButton2 are created by the designer */
CompactButton c = new CompactButton();
c.Enabled = baseButton1.Enabled;
c.Visible = baseButton1.Visible;
c.Name = baseButton1.Name;
CompactButton c2 = new CompactButton();
c2.Enabled = baseButton2.Enabled;
c2.Visible = baseButton2.Visible;
c2.Name = baseButton2.Name;
_compactButtons.Add(c);
_compactButtons.Add(c2);
}
}
ist Ihr Typ namens * CompactButton * oder * CompactButtons *? In Ihrem Code-Snippet bezeichnen Sie es als CompactButton, während Sie in Ihrem Fragetext CompactButtons sagen. –
Mein Typ heißt 'CompactButton'. Ich habe meine Frage bearbeitet. – Martijn
Was ist die Ziel-Framework-Version für Ihr Projekt? Google sagt, dass es einige Probleme gibt, wenn das Ziel das 3.5-Framework ist. – Patko