Open ghost opened 2 years ago
BTW, I do not know why the declarations were outside of the generated-code region, but I preserved/emulated that arrangement in my projects until I find an explanation.
Q. Why is everything fully qulified? A. This must have been to allow for unambiguous identification of objects in the designer, even if 3rd party controls become involved.
Q. Why are the declarations and instantiation and the setting of properties all separated, when there are more compact statements possible? A. This form is as atomic as can be, simplifying the parsing of the code to find the objects, their properties and values, and the event-handlers being assigned to their events.
For more elaborate examples of this arrangement, see
1) https://github.com/sjsepan2/EtoFormsApp2/blob/master/EtoFormsApp2/MainForm.eto.cs in https://github.com/sjsepan2/EtoFormsApp2
2) https://github.com/sjsepan2/MonoApp1/blob/master/MainWindow.Designer.cs in https://github.com/sjsepan2/MonoApp1
Thanks, I took a few of your suggestions in https://github.com/modern-forms/Modern.Forms-Templates/commit/0d334a5695ee577efb4fa8144e932ce2efbe7e4f.
I think it's probably a bit premature to try to figure out how a hypothetical designer would serialize the code, so we'll leave that until a designer exists.
Thanks, I took a few of your suggestions in 0d334a5.
I think it's probably a bit premature to try to figure out how a hypothetical designer would serialize the code, so we'll leave that until a designer exists.
Cool, Thanks. Agreed -- just some notes for possible future reference.
In concert with https://github.com/modern-forms/Modern.Forms/issues/18, it might help to start thinking of a canonical arrangement for the form-definition code in the designer partial-file (
MainForm.Designer.cs
). The one used by the actual WinForms designer seemed to work well for them, so I used that arrangement as a model when starting some new projects on Linux (Eto.Forms+.Net6, WinForms+Mono) where there was not yet a designer, but might be some day. With that in mind, after I opened the project created from Modern.Forms-Templates (dotnet new modernforms
), I re-worked the generated designer-file code to match what the designer might output. The result looks like...Note that the partial class does not need to repeat the public keyword or re-declare the base in order to compile. Note that the partial class does not need the using statements either. Note that the
InitializeComponent
method can be private. The arrangement seemed to be that the declaration of controls is at the bottom, outside theInitializeComponent
call, the instantiation is done at the top ofInitializeComponent
, and then the setting of individual properties, controls configured before the form and then added to it, and everything fully/explicitly qualified. Just some food for thought.