Winform Surface Designer how to generater resx file from component serializer
Asked Answered
F

0

0

I am currently using the System.ComponentModel.Design.Serialization namespace to generate C# code. This code is compiled later by another application.

        var manager = new DesignerSerializationManager(host);
        using (manager.CreateSession())
        {
            var serializer = (TypeCodeDomSerializer)manager.GetSerializer(root.GetType(),
                typeof(TypeCodeDomSerializer));

            type = serializer.Serialize(manager, root, host.Container.Components);
....
        }

This would generate C# code like:

    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TestForm));
        this.SuspendLayout();
        // 
        // TestForm
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
        this.ClientSize = new System.Drawing.Size(800, 450);
        this.Name = "TestForm";
        this.Text = "Form1";
        this.ResumeLayout(false);

    }

Now I am trying to see if I can create an resx file to complement the gerenated code. As you can see with the line:

this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));

This references the resx file but if you try and compiled this line, there is a missing resx file. I've been looking for a serializer for the design surface that does this but I cannot find once.

If anyone has any knowledge on this maybe can point me in the right direction?

Flatfoot answered 23/7, 2021 at 20:9 Comment(2)
Maybe it should be a function of the designer property grid to create the resx file when an object is changed and that property is type serializable.Flatfoot
I have the same issue, did you ever resolve this?Schmitz

© 2022 - 2024 — McMap. All rights reserved.