2

I currently have a C# User Control. It seems that I need to change the order of the designer generated code. GraphControlMode should be set before the graph controls properties as it is responsible for creating the correct controller type.

        // 
        // graphControl2
        // 
        this.graphControl2.Controller.CenterX = ((uint)(623u));
        this.graphControl2.Controller.CenterY = ((uint)(492u));
        this.graphControl2.Controller.ChartDiameter = ((uint)(834u));
        this.graphControl2.Controller.Interval = 100D;
        this.graphControl2.Controller.IsNormalized = false;
        this.graphControl2.Controller.Pause = false;
        this.graphControl2.Controller.Speed = 50D;
        this.graphControl2.Controller.TimeElapsed = 0D;
        this.graphControl2.Controller.View = livePieGraph1;
        this.graphControl2.GraphControlMode = GraphingControl.GraphControl.GraphMode.LIVEPIEGRAPH;

Is there a way to do this?

Eladian
  • 958
  • 10
  • 29
  • Voting to close as a duplicate of [Is it posible to set the order of the serialization of a custom property of a custom component/control in the designer-generated code?](https://stackoverflow.com/questions/30364130/is-it-posible-to-set-the-order-of-the-serialization-of-a-custom-property-of-a-cu) . Both questions are rather old, but I found this one first and wish I'd found the older question, which actually has an answer. – Brian Aug 25 '23 at 13:57

1 Answers1

0

What's the problem? Just cut the line and paste it to the correct position. It's designer generated code and it's still code and not magic.

Timo
  • 9,269
  • 2
  • 28
  • 58
  • 1
    The problem is the designer complains when I move it, and I would rather not have it do that every time the control is copied to a form. By designer complaining I mean, the application then runs... but the form can no longer be rendered because it complains – Eladian Apr 16 '16 at 08:23
  • Is the graphControl2 the UserControl or is this code part of your UserControl? – Timo Apr 16 '16 at 08:32
  • graphControl2 is the User control, the code provided was an extract of what the designer is producing. The problem occurs because the GraphControlMode property when changed creates an object and assigns it to the controller reference. If that is created last, then the controller is null and thus not of the other properties can be set – Eladian Apr 16 '16 at 08:45
  • Im not quite sure about this and I can't test it at the moment but I think the designer generates the property assignments in the order they are defined in your Control. So try to place the GraphControlMode property above the Controller property in your UserControl. If this doesn't work, try to avoid the code generation for the Controller property. This can be done by assigning the [DesignerSerializationVisibility](https://msdn.microsoft.com/en-us/library/ms973818.aspx) attribute: `[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public xyz Controller {get; set;}` – Timo Apr 16 '16 at 10:57
  • @Eladian I just tested it. Just reoder the definition of your properties in your UserControl and you will be fine. – Timo Apr 16 '16 at 11:11
  • I need the controller to be serialized through as the controller provides getters and setters to the model and what ultimately will be accessed through the designer. Also, the definition of "GraphControlMode" is at the top of the user control, what exactly would I change? – Eladian Apr 16 '16 at 12:48
  • 3
    I'm sorry I have to correct myself. The designer orderes the code alphabetically by the name of the property. You could add the `DefaultValue`attribute to your controller and set it to null. This will prevent the designer from initializing the controller. – Timo Apr 16 '16 at 13:05