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

Custom Paint Event

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

    Custom Paint Event

    Hi,

    I have written a custom event in my indicator code. As part of this event, I need to repaint the various graphic objects drawn on the visible part of the chart, which I do via Refresh(). The repaint needs to be done regardless of whether the chart is connected to data from a provider.

    Unfortunately, the chart is not being repainted. I believe the custom event is firing but is being consumed by the form. I can access the window of the chart and attach to its Paint event but this still does not work as there does not seem to be an equivalent to KeyPreview that relates to paint events.

    I realize this is unsupported, but as done for KeyPress previously, can someone please point me in the right direction so that Ican achieve a chart repaint basedon a custom paint event even when disconnected form a data provider? Any suggestions would be greatly appreciated. Thanks.

    #2
    Without knowing exactly what you are doing with your event handlers I recommend that you try taking a look at the Script below. It subscribes to the Paint Event of the chart in which you can then link to your method
    http://www.ninjatrader.com/support/f...atid=6&lpage=1

    Comment


      #3
      Thank you for your suggestion Calonious, and for taking the time to answer it.

      The indicator you suggested is interesting but from the quick look I had at it, it does not seem to be repainting the chart. I am basically looking for a way to subscribe to the paint event of the chart and override it with a custom paint code. I would like to do this from another custom event or as part of an event chain. I know there is a OnPaint() method but it is private and inaccessible. It may be that the only way to go is to override Plot. I would like it if Cal, some certified developer, or anyone who has actually been able to do this provided some input on this subject. Nonetheless, thank you very much for your input. I do appreciate it.

      Comment


        #4
        What are you repainting on the chart? The actual bars or whatever this script is painting?

        The repaint is occurring and the method RePaint will capture that as it is subscribed when a paint event has occurred on the chart such as calling ChartControl.ChartPanel.Invalidate()

        This essentially tells the panel to repaint itself, thus calling the event, which is used in the OnMouseMove() method.


        The Plot() wasn't used for drawing but that can be used exactly for that purpose of custom drawing. The RePaint() uses the PaintEvent to capture when this is called and then uses the Graphics class for all the drawing. Pretty basic usage but does outline how it could be done.
        Last edited by Calonious; 04-21-2015, 04:36 PM.

        Comment


          #5
          Thanks for your reply Calonious.

          I am essentially trying to keep the CPU load down by only painting items that are in the visible portion of the chart. I have a custom event that fires when the chart panel changes and I was attempting to fire a repaint of the items on the chart (lines predominantly at this time) from this (ChartChange) event. I have used (to provide additional data)

          ChartControl.Paint += new System.Windows.Forms.PaintEventHandler((s, e) => this.ChartPaint(s, e, chartChangeData));

          and then simplified it to

          ChartControl.Paint += new System.Windows.Forms.PaintEventHandler(this.ChartP aint);

          but the event still seems to be consumed by the form/panel and does not fire. As an aside, I use this.ChartControl.Refresh() to redraw.

          I will take a closer look at the code you suggested. Thanks for your input.

          Comment


            #6
            ChartControl.ChartPanel.Paint += new PaintEventHandler(RePaint);

            That is what I used to get the paint event for the panel itself.

            Also If you only want to paint in the View-able area you can use ChartControl.FirstBarPainted and LastBarPainted to get the X-Values for those bars and then only paint your resolution/items to draw within that limit.

            Comment


              #7
              Thanks Calonious.
              I know how to handle the viewable area. I think I will rework the code to simplify it, and see if I can chain events in a different way to make this work.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by RubenCazorla, Today, 09:07 AM
              0 responses
              1 view
              0 likes
              Last Post RubenCazorla  
              Started by BarzTrading, Today, 07:25 AM
              2 responses
              28 views
              1 like
              Last Post BarzTrading  
              Started by devatechnologies, 04-14-2024, 02:58 PM
              3 responses
              20 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by tkaboris, Today, 08:01 AM
              0 responses
              6 views
              0 likes
              Last Post tkaboris  
              Started by EB Worx, 04-04-2023, 02:34 AM
              7 responses
              165 views
              0 likes
              Last Post VFI26
              by VFI26
               
              Working...
              X