[RESOLVED] User Control Docking requires saving the form every time it is opened.
I am using VB.NET 4.8.1 and WinForms. Running Visual Studio 2022 on Windows 11
I have created a user control that includes a logo image, three labels, a text box and a button because I want this to appear on all MDI Child forms in the project. Two of the labels are docked. One of them displays the product version and the other forms a wide colored line that is the right boundary of the control. This user control will be docked to the left side of every other form in the project (except the MDI Parent main form).
The issue is that every time I open a form in the designer, something changes and the form wants to be saved. I am not manually making any changes. Just closing and opening the form causes a change. I have been unable to detect what is changing. But it is somehow related to the docking because when I set the dock property to 'none', the issue goes away.
I created a new form and added a button and set it to dock left to test if docking regular controls exhibits this issue. But it worked as expected. Once saved, it does not need to be saved again simply because it is reopened.
Is there something I need to do programmatically to save the state of the user control after it is placed on another form and potentially resizes due to docking?
My issue still occurs if the form the user control is placed on is sized such that the docking doesn't change the initial size of the user control. I can't see any other properties changing that would require the form to be saved.
I do have some code in the load event of the user control that sets the text on the application version label. But I put that code in an 'If Not Me.DesignMode Then' statement so it wouldn't run in the designer but that did not fix the issue.
I have also temporarily turned off docking on the two labels inside my user control. The user control no longer wants to be saved every time it is opened. But every form I put it on does (unless I do not set the user control to dock on the form).
I discovered more information. The issue is only occurring in my forms that have ControlBox set to false. (And the User Control itself) Forms with ControlBox set true do not exhibit the problem. Also, a regular button control set to dock left on a form with ControlBox set false works properly. So the deadly combination seems to be ControlBox set false and my User Control.
Re: User Control Docking requires saving the form every time it is opened.
I tried to recreate this issue in a new project and everything works fine. There must be something corrupted in my original project that is causing this. I don't see a way to delete the original thread but maybe a moderator can delete it so no-one wastes their time reading it further.
Re: User Control Docking requires saving the form every time it is opened.
Just use the Thread Tools menu to mark the thread Resolved, so everyone knows you need no more help without having to open the thread and read it. I have done so for you this time.