Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Save custom form window position with workspace

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Save custom form window position with workspace

    Good evening,

    I have an indicator in a custom form instance that is opened within OnStartup, and I wish to save the form location (window position) with the workspace. This is an unsupported coding level so i am crossing my fingers someone has paved the way.

    I have observed some third party vendors have been able to serialise the form location within the workspace XML. For this to occur one either has to update indicator properties from within the indicator callbacks such as OnTermination, with the form location coordinates in order to serialise the location of the window using the (inbuilt) Ninja XML serialisation code which I assume exists..... Or

    Are they writing to the workspace XML with a seperate XMLSerialize call? If so is there a save workspace callback to do this within?

    I think the first option is most likely how it is done, but I just cannot figure out how to change indicator properties (as viewed in the GridControl) on the fly and do not understand the order of events indicator properties are serialised. Serialisation threads do not cover this btw.

    If I can add a non browsable Location property to my indicator and update it as my form is moved, this should do the trick, however I am thinking the Indicator properties cannot be written to after the Indicator Initialize method has completed.

    Thank you for any assistance.

    #2
    Example of how to do it

    Leaning on this kind post by Josh: http://ninjatrader.com/support/forum...ead.php?t=4977

    This is how you can save Window Form location with the workspace:

    public class WindowExample: Indicator
    {
    #region Variables

    CustomForm myForm;
    private Point WinPos;
    ....
    #endregion

    protected override void OnStartUp()
    {
    myForm = new CustomForm();
    myForm.Location = WinPos;
    ...
    }

    ..

    #region Properties
    [XmlIgnore()]
    [Description("Location of Window")]
    [GridCategory("Parameters")]
    public Point WindowPosition
    {
    get { return WinPos; }
    set { WinPos = value; }
    }
    [Browsable(false)]
    public string WindowPositionSerialize
    {
    get
    {
    // Create the PointConverter.
    System.ComponentModel.TypeConverter converter = System.ComponentModel.TypeDescriptor.GetConverter( typeof(Point));

    return converter.ConvertToString(myForm.Location);

    }
    set
    {
    // Create the PointConverter.
    System.ComponentModel.TypeConverter converter = System.ComponentModel.TypeDescriptor.GetConverter( typeof(Point));

    WinPos = (Point) converter.ConvertFromString(value);

    }
    }
    #endregion
    ....
    }
    }


    More information on PointConveter can be found:



    Enjoy.
    Last edited by graham; 07-28-2013, 08:50 PM.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by poplagelu, Today, 05:00 AM
    0 responses
    3 views
    0 likes
    Last Post poplagelu  
    Started by fx.practic, 10-15-2013, 12:53 AM
    5 responses
    5,407 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Started by Shai Samuel, 07-02-2022, 02:46 PM
    4 responses
    98 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Started by DJ888, Yesterday, 10:57 PM
    0 responses
    8 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by MacDad, 02-25-2024, 11:48 PM
    7 responses
    160 views
    0 likes
    Last Post loganjarosz123  
    Working...
    X