• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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:

    http://msdn.microsoft.com/en-us/libr...converter.aspx

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

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by dr0832, 01-04-2019, 10:34 AM
    7 responses
    141 views
    0 likes
    Last Post Lancer
    by Lancer
     
    Started by cbentrikin, Today, 07:46 PM
    0 responses
    4 views
    0 likes
    Last Post cbentrikin  
    Started by RedDuke, Today, 06:14 PM
    0 responses
    4 views
    0 likes
    Last Post RedDuke
    by RedDuke
     
    Started by DariusDeck, Today, 04:22 PM
    1 response
    13 views
    0 likes
    Last Post NinjaTrader_Marco  
    Started by pstrusi, Today, 05:05 PM
    1 response
    3 views
    0 likes
    Last Post pstrusi
    by pstrusi
     
    Working...
    X