NexusFi: Find Your Edge


Home Menu

 





Add Control to Chart - vvhg needs coding help


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one spinnybobo with 2 posts (3 thanks)
    2. looks_two DavidHP with 1 posts (0 thanks)
    3. looks_3 vvhg with 1 posts (0 thanks)
    4. looks_4 Xav1029 with 1 posts (2 thanks)
    1. trending_up 3,617 views
    2. thumb_up 11 thanks given
    3. group 4 followers
    1. forum 6 posts
    2. attach_file 2 attachments




 
Search this Thread

Add Control to Chart - vvhg needs coding help

  #1 (permalink)
 
vvhg's Avatar
 vvhg 
Northern Germany
 
Experience: Intermediate
Platform: NT
Trading: FDAX, CL
Posts: 1,583 since Mar 2011
Thanks Given: 1,016
Thanks Received: 2,824

I am trying to add a control (a TextBox in this example) to a chart.
Unfortunately everything I have tried so far creates a textbox about the size of the toolbar



 
Code
Form thechart = ChartControl.FindForm();
				
				if (thechart != null)
				{
					textBox2 = new System.Windows.Forms.TextBox();
					textBox2.Dock = DockStyle.Fill;
					textBox2.Visible = true;
					textBox2.Location = new System.Drawing.Point(500, 500);
					textBox2.Size = new System.Drawing.Size(750, 500);
					textBox2.Text = "ChartBox";
					thechart.Controls.Add(textBox2);
					textBox2.BringToFront();
				}
I also tried ChartControl.ChartPanel.FindForm() but the result is the same...

To all the geniuses out there...e.g. @gomi, @Xav1029, @Fat Tails, @1LotTrader, @monpere, @ThatManFromTexas, @Silvester17, @NJAMC and all the others...

vvhg

Hic Rhodos, hic salta.
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Build trailing stop for micro index(s)
Psychology and Money Management
Exit Strategy
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Futures True Range Report
The Elite Circle
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
60 thanks
Funded Trader platforms
37 thanks
NexusFi site changelog and issues/problem reporting
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
19 thanks
  #3 (permalink)
 
Xav1029's Avatar
 Xav1029 
Tampa, FL
 
Experience: Beginner
Platform: NinjaTrader, Sierra Chart
Broker: Mirus Futures/Zen-Fire
Trading: 6E, M6E, 6J
Posts: 1,375 since Dec 2011
Thanks Given: 1,452
Thanks Received: 3,377


@vvhg I am currently on a programming hiatus and have never done this before, however I know you are a quick learner so take a look at . This uses a dropdown menu to add functionality.

London Calling
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 
ktrader's Avatar
 ktrader 
glostrup, denmark
 
Experience: Advanced
Platform: Custom platform
Broker: CQG
Trading: Futures, Options, Stocks
Posts: 249 since Aug 2011
Thanks Given: 152
Thanks Received: 275


vvhg View Post
I am trying to add a control (a TextBox in this example) to a chart.
Unfortunately everything I have tried so far creates a textbox about the size of the toolbar



 
Code
Form thechart = ChartControl.FindForm();
			

				if (thechart != null)
				{
					textBox2 = new System.Windows.Forms.TextBox();
					textBox2.Dock = DockStyle.Fill;
					textBox2.Visible = true;
					textBox2.Location = new System.Drawing.Point(500, 500);
					textBox2.Size = new System.Drawing.Size(750, 500);
					textBox2.Text = "ChartBox";
					thechart.Controls.Add(textBox2);
					textBox2.BringToFront();
				}
I also tried ChartControl.ChartPanel.FindForm() but the result is the same...

To all the geniuses out there...e.g. @gomi, @Xav1029, @Fat Tails, @1LotTrader, @monpere, @ThatManFromTexas, @Silvester17, @NJAMC and all the others...

vvhg

HI,

You can do something like this:

 
Code
      protected override void Initialize()
        {
            Overlay				= true;
     	     Form thechart = ChartControl.FindForm();
			System.Windows.Forms.Panel cc = new System.Windows.Forms.Panel();
			Label ll = new Label();
			ll.Text="hello";
			cc.Controls.Add(ll);
			cc.Anchor=AnchorStyles.Bottom ;
			cc.Dock = DockStyle.Bottom;
			
			thechart.Controls.Remove(ChartControl);
			thechart.Controls.Add(ChartControl);
			thechart.Controls.Add(cc);
	
		}
will look like:



--ktrader

Reply With Quote
  #5 (permalink)
 
spinnybobo's Avatar
 spinnybobo 
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
Posts: 173 since Aug 2009
Thanks Given: 105
Thanks Received: 61

Hello

this is the best way

 
Code
    // Variables
    private ToolStrip strip = null;
    private Control[] controls = null;
    private ToolStripTextBox tstbSpencer;
    private bool buttonsLoaded = false;
    private Font regularFont = null;

    private ToolStripButton btnSubmit= null;

	public override void Dispose() // these are taken off when chart is refreshed so no multiple objects
	{
		if (buttonsLoaded == true)
		{
			strip.Items.Remove(btnSubmit);
			strip.Items.Remove(tstbSpencer);
		}
	}
        protected override void Initialize()
        {
			CalculateOnBarClose = true;
			regularFont = new Font("Arial", 8);
        }
        // this is the event that happens when button is clicked.  
	private void btnSubmit_Click(object sender, EventArgs e)
	{
		
		MessageBox.Show(tstbSpencer.Text.ToString());
				
	}
        protected override void OnStartUp()
	{
		controls = ChartControl.Controls.Find("tsrTool", false);
			
		if (controls.Length > 0)
		{
			btnSubmit= new ToolStripButton();
			btnSubmit.Font = regularFont;
        		btnSubmit.ForeColor = Color.Black;
			btnSubmit.BackColor = Color.Green;
			btnSubmit.Text = "Submit";
			strip = (ToolStrip)controls[0];
				
			btnSubmit.Click += btnSubmit_Click; // register event
				
			tstbSpencer = new ToolStripTextBox();
			tstbSpencer.Size = new System.Drawing.Size(100, 20);
				
			strip.Items.Add(tstbSpencer); // add ToolStripTextBox to the ToolStrip
                        strip.Items.Add(btnSubmit); // add button to the ToolStrip
				
			buttonsLoaded = true;
		}
	}
that is pretty much it.

I found out how to add a button from NinjaTrader's example using the

 
Code
controls = ChartControl.Controls.Find("tsrTool", false);
for the TextBox I googled ToolStrip and TextBox and found ToolStripTextBox
I then opened visual studio and created a Forms project and then added a ToolStrip, then added a TextBox

Then I opened the GUI code Form.Designer.cs
and found out what the code behind it was using
I then simply added that code here in which case was just specifying a size

anyway, that is the logic behind making it work is add it in visual studio and grab that code and try to fit it in here

Follow me on Twitter Reply With Quote
Thanked by:
  #6 (permalink)
 
DavidHP's Avatar
 DavidHP 
Isla Mujeres, MX
Legendary Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Ninjatrader / Optimus Futures / AmpFutures
Trading: ES / 6E / 6B / CL
Frequency: Every few days
Duration: Minutes
Posts: 1,609 since Aug 2009
Thanks Given: 11,328
Thanks Received: 2,743

Can you post an image of the result?



spinnybobo View Post
Hello
this is the best way

 
Code
    // Variables
    private ToolStrip strip = null;
    private Control[] controls = null;
    private ToolStripTextBox tstbSpencer;
    private bool buttonsLoaded = false;
    private Font regularFont = null;

    private ToolStripButton btnSubmit= null;

	public override void Dispose() // these are taken off when chart is refreshed so no multiple objects
	{
		if (buttonsLoaded == true)
		{
			strip.Items.Remove(btnSubmit);
			strip.Items.Remove(tstbSpencer);
		}
	}
        protected override void Initialize()
        {
			CalculateOnBarClose = true;
			regularFont = new Font("Arial", 8);
        }
        // this is the event that happens when button is clicked.  
	private void btnSubmit_Click(object sender, EventArgs e)
	{
		
		MessageBox.Show(tstbSpencer.Text.ToString());
				
	}
        protected override void OnStartUp()
	{
		controls = ChartControl.Controls.Find("tsrTool", false);
			
		if (controls.Length > 0)
		{
			btnSubmit= new ToolStripButton();
			btnSubmit.Font = regularFont;
        		btnSubmit.ForeColor = Color.Black;
			btnSubmit.BackColor = Color.Green;
			btnSubmit.Text = "Submit";
			strip = (ToolStrip)controls[0];
				
			btnSubmit.Click += btnSubmit_Click; // register event
				
			tstbSpencer = new ToolStripTextBox();
			tstbSpencer.Size = new System.Drawing.Size(100, 20);
				
			strip.Items.Add(tstbSpencer); // add ToolStripTextBox to the ToolStrip
                        strip.Items.Add(btnSubmit); // add button to the ToolStrip
				
			buttonsLoaded = true;
		}
	}
that is pretty much it.

I found out how to add a button from NinjaTrader's example using the

 
Code
controls = ChartControl.Controls.Find("tsrTool", false);
for the TextBox I googled ToolStrip and TextBox and found ToolStripTextBox
I then opened visual studio and created a Forms project and then added a ToolStrip, then added a TextBox

Then I opened the GUI code Form.Designer.cs
and found out what the code behind it was using
I then simply added that code here in which case was just specifying a size

anyway, that is the logic behind making it work is add it in visual studio and grab that code and try to fit it in here


Rejoice in the Thunderstorms of Life . . .
Knowing it's not about Clouds or Wind. . .
But Learning to Dance in the Rain ! ! !
Follow me on Twitter Reply With Quote
  #7 (permalink)
 
spinnybobo's Avatar
 spinnybobo 
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
Posts: 173 since Aug 2009
Thanks Given: 105
Thanks Received: 61


DavidHP View Post
Can you post an image of the result?

Hello

yes here is an image of the result. sorry it took a while

Attached Thumbnails
Click image for larger version

Name:	textbox pic.PNG
Views:	280
Size:	110.4 KB
ID:	187798  
Follow me on Twitter Reply With Quote
Thanked by:




Last Updated on July 21, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts