• 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

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 Duval, Today, 08:38 AM
            0 responses
            8 views
            0 likes
            Last Post Duval
            by Duval
             
            Started by i2w8am9ii2, 02-13-2019, 04:28 PM
            7 responses
            61 views
            0 likes
            Last Post sledge
            by sledge
             
            Started by woodyfox, Yesterday, 08:33 PM
            0 responses
            8 views
            0 likes
            Last Post woodyfox  
            Started by rblunsom, Yesterday, 11:19 AM
            2 responses
            30 views
            0 likes
            Last Post guidoisot  
            Started by drewski1980, Yesterday, 02:38 PM
            1 response
            23 views
            0 likes
            Last Post NinjaTrader_ChrisL  
            Working...
            X