Custom development time

I want to create my own TabControl class with development-time support.

This is my designer:

public class TabListDesigner : ParentControlDesigner
{
    protected TabList TabListControl { get { return this.Control as TabList; } }

    protected override void WndProc(ref Message m)
    {
        switch (m.Msg)
        {
            case 0x7b: // WM_CONTEXTMENU
                this.OnContextMenu(Cursor.Position.X, Cursor.Position.Y);
                break;
            default:
                base.WndProc(ref m);
                break;
        }
    }

    protected override bool GetHitTest(Point point)
    {
        return this.TabListControl.HitTest(this.TabListControl.PointToClient(point)) != null;
    }

    protected override void OnPaintAdornments(PaintEventArgs pe)
    {
        base.OnPaintAdornments(pe);
        ControlPaint.DrawFocusRectangle(pe.Graphics, this.Control.ClientRectangle);
    }

    public override void InitializeNewComponent(IDictionary defaultValues)
    {
        base.InitializeNewComponent(defaultValues);
        this.AddTabListPage();
        this.AddTabListPage();
    }

    protected virtual void AddTabListPage()
    {
        IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost));

        if (host != null)
        {
            using (DesignerTransaction transaction = host.CreateTransaction(string.Format("Add TabListPage to '{0}'", this.TabListControl.Name)))
            {
                try
                {
                    TabListPage page = (TabListPage)host.CreateComponent(typeof(TabListPage));
                    MemberDescriptor controlsProperty = TypeDescriptor.GetProperties(this.TabListControl)["Controls"];

                    this.RaiseComponentChanging(controlsProperty);

                    this.TabListControl.Add(page);
                    this.TabListControl.Controls.Add(page);

                    this.RaiseComponentChanged(controlsProperty, null, null);

                    transaction.Commit();
                }
                catch
                {
                    transaction.Cancel();
                    throw;
                }
            }
        }
    }
}

In the designer, I add my Tabcontrol to the form and 2 tabs are displayed correctly. Now I am testing the project and 2 tabs disappear. I am returning to the designer, and Tabpages is no more. What for?

+5
source share
1 answer

I once created a control designer, not the ones that the form designer uses, but more like the actual form designer for a single control. I don’t remember very well from the project, but I remember that I had the same problem, and I had to warn the visual studio that I had somehow changed its meaning.

, visual studio . codeDom, .

, , , , . , , acient #, "Shape designer" - . . , . , , .

, , . vb.net, , .

, , gif

EDIT:

"DesignerControl.vb" 187:

' The controldesigner don't always save properties which are changed directly :/
Private Sub SetValue(itm As Item, pName$, val As Object)
    Dim Prop As PropertyDescriptor = TypeDescriptor.GetProperties(itm.Page)(pName)
    If Prop IsNot Nothing AndAlso Prop.PropertyType Is val.GetType Then Prop.SetValue(itm.Page, val)
End Sub
0

All Articles