0

This is a troubleshooting question. I hope this is considered a valid question for this forum. If not then please advise where I should move this question to. Also, this question is in addition to a question I asked here: .NET 5 Windows Forms with Dependency Injection - How to pass form properties from one form to another?

I am upgrading a .NET Framework Windows Form Application to .NET 5 using Dependency Injection (DI). The application has a form that uses a data factory in order to have other form parameters passed into it (see question link above) and it is also restricted by the Active Directory (AD) group a user is in. When the form's constructor calls it's InitializeComponent() method, all of the text box fields and labels come back with their Enabled property set to false, whereas in the .NET Framework version they come back as true. Why is this happening?

Troubleshooting:

I copied the code from <fileName>.Design.cs from both versions and ran a compare (using Notepad ++) on them. But, I did not see any change between the two that would lead me to conclude why the form's text boxes and tabs are coming back disabled. There are differences, but those only pertain to cell padding values, which I do not believe is causing the problem.

I checked Microsoft's .NET 5 Migration compatibility site for any potential breaking changes that might apply, but I did not see anything that stood out.

I have tried manually setting a form's TextBox Enable property to true, but this did not work. Plus, I don't think this is a good idea because it might break other functionality by potentially overriding some other behavior that locks a fields Enabled property.

this.textATtest.Enabled = true;

This returns false after the breakpoint in runtime.

All other forms in this .NET 5 solution are functioning and displaying properly. The only real difference that I can see between the current form and other forms in the project is that it implements a data factory to pass in form parameters and restricts what users can access it base on what AD security group they are in. But, I don't think this is causing the problem because I am able to access the form just fine in the .NET Framework version.

Does anyone know how I can troubleshoot this problem? I have no idea how else the InitializeComponent() method sets a forms properties other than in the <FileName>.Design.cs file. Any help is greatly appreciated.

J Weezy
  • 3,507
  • 3
  • 32
  • 88
  • 1
    UI elements of a Form that are not explicitly set to `Enabled = false` in the designer, are set to `Enabled = false` after `InitializeComponent()` completes if the Form itself is disabled. If the Form is disabled after it has been initialized, Control are set to `Enabled = True` in the Constructor, but `Enabled = false` when the Form loading is complete (in `OnLoad()`). – Jimi Mar 22 '21 at 14:50
  • @Jimi ... o_O Wow! That worked. If you post that as the answer I will accept it. From what I can tell, the .NET Framework project does not explicitly set the form's enabled property to true within the `.Designer.cs` file. When the upgrade to .NET 5 occurred, it automagically added the `Enabled` property it and set it to `false`. When re-checking the compare, the diff is in there and I just missed it. I was scrutinizing the individual form elements and not the form itself. Thank you! – J Weezy Mar 22 '21 at 15:04
  • 1
    Well, I'm glad that the hint could fix the immediate problem, but I don't think that it's actually an answer. If it was, then the question should be closed as `Problem Not Reproducible or a Typo`. If you can confirm that the problem is directly caused by the default migration tool and not something else more trivial, then post yourself your findings. I have no notion of this or previously experienced such behavior. If this is actually what happened, that's the interesting part. – Jimi Mar 22 '21 at 15:26

0 Answers0