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

Updating a form

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

    Updating a form

    Hey everyone,

    This isn't a NinjaScript question, but I'm hoping someone out there can throw me a bone.

    I've created a custom chart of a statistical distribution. I create the graphic and it works fine when I save it to file.

    What I want to do is to display the graphic in a separate form that I've created and to update it once per bar. My problem is with the updating - I can't figure out how to pass my Graphics object to my form1 object in order to make it paint.

    Things I tried:
    Setting e.Graphics equal to a class variable hoping it would "stick" to the form from OnBarUpdate(). No such luck.
    Setting a panel on the form, then updating the panel BackgroundImage property from OnBarUpdate(). I don't see anything "goldenrod" in the background, so maybe this is the avenue and I messed it up. I'm at the point where I'm frustrated and not thinking clearly. Help is much appreciated!

    Code:
        public class HurstBars : Indicator
        {
            private Form1 form1;
    
            protected override void OnStartUp()
            {
                form1 = new Form1();
                form1.Show();    
            }
            
            protected override void OnTermination()
            {
                form1.Dispose();    
            }
    
            protected override void OnBarUpdate()
            {
                Bitmap bmp = new Bitmap(width,height);
                Graphics g = Graphics.FromImage( bmp );
    
                // do operations on g
                // ....
    
                form1.ImagePanel.BackgroundImage = bmp;            
                form1.G = g;
            }          
        }
    
        public class Form1 : Form
        {
            private Graphics g;
            
            private Panel panel;
            private Image image;
            
            public Form1()
            {
                //InitializeComponent();
                this.Text = "Initial title";
                this.Height = 600;
                this.Width = 800;
                
                this.Load += new System.EventHandler(this.Form1_Load);
                this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
                
                panel = new Panel();
            }
            
            private void Form1_Paint(object sender, PaintEventArgs e)
            {
                this.Text = "Painted form";
                
                Graphics temp = e.Graphics;
                temp = g;
            }
            
            private void Form1_Load(object sender, EventArgs e)
            {
                //this.Text = "New title";        
                panel.Width = 800;
                panel.Height = 600;
                panel.BackColor = Color.PaleGoldenrod;
                panel.Location = new System.Drawing.Point(0, 0);
                panel.BackgroundImage = image;            
            }
    
    
    
            private void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
    
            }
            
            public Graphics G
            {
                get    {    return g;    }
                set    {    g = value;    }
            }
            
            public Panel ImagePanel
            {
                get{ return panel; }
                set{ panel = value; }
            }
        }
    Any suggestions?

    #2
    I figured it out. You put this line in Form1_Paint():

    Code:
    e.Graphics.DrawImage(new Bitmap("C:\\formImage.jpg"),new PointF(0.0F, 0.0F));
    Then, in OnBarUpdate(), you force the form to repaint itself:

    Code:
    form1.Invalidate();

    Comment


      #3
      Hi texasnomad,

      Thanks for posting this situation and the resolution you found. I'm sure other members will benefit from this technique.
      Ryan M.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by texasnomad View Post
        I figured it out. You put this line in Form1_Paint():

        Code:
        e.Graphics.DrawImage(new Bitmap("C:\\formImage.jpg"),new PointF(0.0F, 0.0F));
        Then, in OnBarUpdate(), you force the form to repaint itself:

        Code:
        form1.Invalidate();
        Sounds like the same technique should be able to allow one to capture an image of the chart with all its objects, as we were looking at in that other thread: http://www.ninjatrader.com/support/f...ad.php?t=46469

        Have you tried it?

        Comment


          #5
          Yes, I can't get the chart graphic in the first place. Check out the thread that you linked to.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by bortz, 11-06-2023, 08:04 AM
          47 responses
          1,602 views
          0 likes
          Last Post aligator  
          Started by jaybedreamin, Today, 05:56 PM
          0 responses
          8 views
          0 likes
          Last Post jaybedreamin  
          Started by DJ888, 04-16-2024, 06:09 PM
          6 responses
          18 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by Jon17, Today, 04:33 PM
          0 responses
          4 views
          0 likes
          Last Post Jon17
          by Jon17
           
          Started by Javierw.ok, Today, 04:12 PM
          0 responses
          12 views
          0 likes
          Last Post Javierw.ok  
          Working...
          X