Skip to content

.NET 5.0 OnCreateHandle override isn't called #4451

Description

@chris-steema
  • .NET Core Version:

Microsoft.NETCore.App.Ref v5.0.0
Microsoft.WindowsDesktop.App.Ref v5.0.0

  • Have you experienced this same bug with .NET Framework?:

No.

Problem description:

When I build this control in .NET Framework and then drag it onto a .NET Framework Windows Form design surface, OnCreateHandle is called and the MessageBox is shown. However, when I build this control in .NET 5.0 (net5.0-windows) with UseWindowsForms true and then drag it onto a .NET 5.0 Windows Forms design surface, OnCreateHandle is not called and the MessageBox does not show.

Expected behavior:

I would expect OnCreateHandle to be called in .NET 5.0 in the same way as it is called in .NET Framework 4.6

Minimal repro:

[Designer(typeof(TestDesigner))]
public class NETFrameworkControl : Control
{
    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);

        e.Graphics.FillRectangle(Brushes.Red, e.ClipRectangle);
    }

    public class TestDesigner : System.Windows.Forms.Design.ControlDesigner
    {
        protected override void OnCreateHandle()
        {
            base.OnCreateHandle();
            MessageBox.Show("OnCreateHandle");
        }
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-VSDesignerWindows Forms out-of-proc designer related issues

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions