У меня есть настраиваемый элемент управления с общим списком настраиваемых типов. Этот список определяется общественностью:C# Winforms Дизайнер Visual Studio не может найти настраиваемый тип
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Editor(typeof(ButtonPanelXEditor), typeof(UITypeEditor))]
public List<CompactButton> CompactButtons
{
get { return _compactButtons; }
set { _compactButtons = value; }
}
Когда я добавить этот элемент управления для моей формы и построить мой проект, я получаю эту ошибку:
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
Когда я использую строки вместо пользовательских объектов, то desginer ли сохранить мой список. CompactButton
имеет атрибут [Serializable]
и берет начало с ISerializable
Что можно сделать, чтобы исправить это?
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);
}
}
Ваш тип с именем * CompactButton * или * CompactButtons *? В своем фрагменте кода вы ссылаетесь на него как на CompactButton, в то время как в вашем текстовом вопросе вы указываете CompactButtons. –
Мой тип называется 'CompactButton'. Я отредактировал мой вопрос. – Martijn
Какова целевая версия рамки для вашего проекта? Google говорит, что есть некоторые проблемы, если целью является 3.5. – Patko