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

MessageBox.Show , dispose, termination issues

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

    MessageBox.Show , dispose, termination issues

    I created a messagebox that will ask the user if they want to save their data.

    I tried the logic in 2 places

    protected override void OnTermination()
    and the logic doesn't work


    public override void Dispose()
    it triggers twice but also if i change times or instruments it will always ask.
    What I want is when the user closes the chart (x) button top right when the function will trigger. How can I do this?



    if (bSaveData == true)
    {

    DialogResult result1= MessageBox.Show("Save your file?","my message box"

    , MessageBoxButtons.YesNo
    , MessageBoxIcon.Information
    , MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);

    if(result1 == DialogResult.Yes )
    {
    writeTradeFile();
    }
    }

    #2
    Hello ballboy11,

    Thanks for your question.

    OnTermination() is intended for resource cleanup and we do not typically advise to override the Dispose() method.

    This would certainly be possible in the context of pure C#, but it would not be a concept we would provide support for.

    I was able to create my own FormClosingEvent method subscribed to ChartControl.PartentForm.FormClosing. I'll include some sample code in this post, but I must be clear that this is not a concept we would support or provide further direction with. You'll be on your own for these sorts of implementations.

    Code:
    using System.Windows.Forms;
    
    ...
    
    public void FormClosingEvent(object sender, FormClosingEventArgs e)
    {
    	Print("Closing");
    }
    
    protected override void OnStartUp()
    {
    	this.ChartControl.ParentForm.FormClosing += new System.Windows.Forms.FormClosingEventHandler(FormClosingEvent);
    }
    Microsoft's C# reference will provide further insight for the FormClosingEventHandler. The Intellisence information provided in the NinjaScript Editor can also provide some hints to implementing unsupported code.

    MSDN FormClosing Event - https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    Intellisence in the NinjaScript Editor - https://ninjatrader.com/support/help...tellisense.htm

    I'll leave this thread open ended if any other forum members would like to share their input.
    JimNinjaTrader Customer Service

    Comment


      #3
      It works great excep if you switch to different time frames so when you go to a 1 minute to 3 mute to 5 minute back to one it records how many times so when you close it will ask the same number of times you switched the timeframes

      Comment


        #4
        Hello ballboy11,

        We don't offer a supported means to detect when a chart's data series changes, and I do not know of any unsupported means I could point you to to provide further direction.

        Perhaps another member of the forums has come up with an approach and would like to share their input.
        JimNinjaTrader Customer Service

        Comment


          #5
          understood

          Comment


            #6
            Solved

            public void FormClosingEvent(object sender, FormClosingEventArgs e)
            {
            try
            {
            // your logic goes here

            this.ChartControl.ParentForm.Dispose();

            }
            finally
            {
            // this is needed or the event will fire twice
            this.ChartControl.ParentForm.FormClosing -= FormClosingEvent;
            }

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DJ888, 04-16-2024, 06:09 PM
            4 responses
            12 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by terofs, Today, 04:18 PM
            0 responses
            7 views
            0 likes
            Last Post terofs
            by terofs
             
            Started by nandhumca, Today, 03:41 PM
            0 responses
            6 views
            0 likes
            Last Post nandhumca  
            Started by The_Sec, Today, 03:37 PM
            0 responses
            3 views
            0 likes
            Last Post The_Sec
            by The_Sec
             
            Started by GwFutures1988, Today, 02:48 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Working...
            X