# .NET 7 and WinForms designer

**URL:** <https://forum.alternetsoft.com/t/net-7-and-winforms-designer/412>\
**Category:** AlterNET Studio Support\
**Created:** [August 16, 2023, 4:13pm UTC](https://forum.alternetsoft.com/t/net-7-and-winforms-designer/412 "2023-08-16T16:13:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergey.Mishkovskiy](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/s/606060/32.png) [@Sergey.Mishkovskiy](https://forum.alternetsoft.com/u/Sergey.Mishkovskiy)\
**Post date:** [August 16, 2023, 4:13pm UTC](https://forum.alternetsoft.com/t/net-7-and-winforms-designer/412/1 "2023-08-16T16:13:12Z")

</div>

Hi,

Does the latest .NET 7 compatible version of Alternet support Toolbox drag and drop?

Thanks.

---

<div class="post-metadata">

**Author:** ![dmitry.medvedev](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/dmitry.medvedev/32/27_2.png) [@dmitry.medvedev](https://forum.alternetsoft.com/u/dmitry.medvedev)\
**Post date:** [August 17, 2023, 3:25am UTC](https://forum.alternetsoft.com/t/net-7-and-winforms-designer/412/2 "2023-08-17T03:25:45Z")

</div>

Hi Sergey,

If I understand the question correctly, you’re asking about our WinForms Form Designer control compiled with .NET 7?

If so, there was an issue with adorner windows in .NET 7, causing issues with control resizing and drag-drop.

> <https://github.com/dotnet/winforms/issues/9160>
>
> \### .NET version
> 
> .NET Core 7
> 
> \### Did it work in .NET Framework?
> 
> Yes
> 
> \### Did …it work in any of the earlier releases of .NET Core or .NET 5+?
> 
> Works fine for .NET 6
> 
> \### Issue description
> 
> We use .NET System.Windows.Forms.Design services for the run-time implementation of the Form designer functionality.
> Form designer works fine in .Net core 6 (and .net 4.62), allowing placing and resizing controls on the design surface. However, resizing does not work with .net 7.
> 
> 
> 
> \### Steps to reproduce
> 
> It would be hard to give a reproducible scenario, but by tracing the source code, we've found the following:
> 
> .NET 6
> BehaviorService.cs
> ...
> private bool ProcessMouseMessage(IntPtr hWnd, Interop.User32.WM msg, int x, int y)
> Point point = new Point(x, y);
> Interop.User32.MapWindowPoints(IntPtr.Zero, adornerWindow.Handle, ref point, 1U);
> Message message = Message.Create(hWnd, msg, (IntPtr)0, Interop.PARAM.FromLowHigh(p.Y, p.X));
> 
> .NET 7
> 
> BehaviorService.cs
> ...
> private bool ProcessMouseMessage(IntPtr hWnd, Interop.User32.WM msg, int x, int y)
> Point point = new Point(x, y);
> adornerWindow.PointToClient(p); // should be p =adornerWindow.PointToClient(p);
> Message message = Message.Create(hWnd, msg, (IntPtr)0, Interop.PARAM.FromLowHigh(p.Y, p.X));
> 
> adornerWindow.PointToClient internally uses MapWindowPoints, but its result is ignored. This is causing sending screen coordinates to the adornerWindow and clearing \_hitTestedGlyph field, which results in adorners not behaving as they should.
> The same applies to the designer action glyph (displayed at the top right corner of the selected control) - it does nothing on our tests.

On our tests, it has been fixed in the latest versions (starting with .NET 7.0.9 )

Please let me know if this is not what yo meant.

Kind regards,  
Dmitry

---

<div class="post-metadata">

**Author:** ![Sergey.Mishkovskiy](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/s/606060/32.png) [@Sergey.Mishkovskiy](https://forum.alternetsoft.com/u/Sergey.Mishkovskiy)\
**Post date:** [August 17, 2023, 12:56pm UTC](https://forum.alternetsoft.com/t/net-7-and-winforms-designer/412/3 "2023-08-17T12:56:42Z")

</div>

Dmitry,

Thanks for your reply. I should’ve expanded on my original question. Looks like WinForms designer toolbox works on .NET 7 windows apps (based on your reply). Expanded part is if you could point me at non-.NETFramewok, ie .NET 6 or 7, demo of WinForms toolbox integration I can play with, and also point out drag and drop initiation and handling on your toolbox implementation source code side I’d appreciate it.

A bit of background on that. My understanding is that SerializeAttribute’s been largely removed from most of .NET 7 classes, including ToolboxItem. On top of that binary formatter is obsolete now. Both of those pieces are used by DataObject and ToolboxItems classes when extracting the data from the dragged item. At least that’s how it works in .NET Framework designer stack. Reason for that is that WinForms designer expects drag and drop to adhere to a certain format, something that cannot be changed my understanding.

So I’m wondering if you made it work, somehow. Thanks.

---

<div class="post-metadata">

**Author:** ![dmitry.medvedev](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/dmitry.medvedev/32/27_2.png) [@dmitry.medvedev](https://forum.alternetsoft.com/u/dmitry.medvedev)\
**Post date:** [August 18, 2023, 9:12am UTC](https://forum.alternetsoft.com/t/net-7-and-winforms-designer/412/4 "2023-08-18T09:12:01Z")

</div>

Hi Sergey,

We use DesignerHost’s serialization mechanism to serialize ToolboxItem into DataObject.  
Here’s the relevant code:

```auto
        private void StartDragAndDrop()
        {
            var dataObject = contentControl.ContentControlSite.SerializeItemForDragAndDrop(contentControl.SelectedItem);
            try
            {
                if (dataObject != null)
                    DoDragDrop(dataObject, DragDropEffects.Copy);
            }
            catch (Exception ex)
            {
                MessageBoxHandler.Show(ex.Message, ErrorMessages.ToolboxDragAndDropError, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        DataObject IToolboxContentControlSite.SerializeItemForDragAndDrop(ToolboxItem item)
        {
            if (DesignerHost == null)
                return CreateItemDataObjectForNoDesigner(item);

            return DesignerHost.Resolve<IToolboxService>().SerializeToolboxItem(item) as DataObject;
        }

```

Let me know if this is what you’re looking for.

Regards,  
Dmitry
