Но когда я создаю проект и ControlLibrary, дизайнер форм Visual Studio не использует ControlDesigners из ControlLibrary, хотя я правильно привязываю дизайнеров к компоненту.
Код: Выделить всё
[Designer(typeof(MyControlDesigner))]
[ToolboxItem(true)]
public class MyControl : Control
{
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.FillRectangle(SystemBrushes.Info, new Rectangle(0, 0, Width, Height));
e.Graphics.DrawString("MyControl", Font, SystemBrushes.InfoText, new PointF(0, 0));
}
}
Код: Выделить всё
namespace WinFormsControlLibrary1
{
internal class MyControlDesigner : ControlDesigner
{
private DesignerActionListCollection actionLists;
public override DesignerActionListCollection ActionLists
{
get
{
if (actionLists == null)
{
actionLists = new DesignerActionListCollection();
actionLists.Add(new DataAxisGridActionList(Component));
actionLists.AddRange(base.ActionLists);
}
return actionLists;
}
}
}
public class DataAxisGridActionList : DesignerActionList
{
public DataAxisGridActionList(IComponent component) : base(component)
{
}
public override DesignerActionItemCollection GetSortedActionItems()
{
DesignerActionItemCollection items = new DesignerActionItemCollection();
items.Add(new DesignerActionMethodItem(this, "Action1", " Action 1", true));
items.Add(new DesignerActionMethodItem(this, "Action2", "Action 2", true));
return items;
}
public void Action1()
{
MessageBox.Show("Action 1");
}
public void Action2()
{
MessageBox.Show("Action 2");
}
}
}


Я также прилагаю ссылку на демо-проекты.
https://github.com/dmitrybv/WinForms-Net5-Designers
https://github.com/dmitrybv/WinForms-Ne ... -Designers
Подробнее здесь: https://stackoverflow.com/questions/768 ... in-net-6-0
Мобильная версия