Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Add Control to Chart - vvhg needs coding help
Updated July 21, 2015
Top Posters
looks_one
spinnybobo
with 2 posts (3 thanks)
looks_two
DavidHP
with 1 posts (0 thanks)
looks_3
vvhg
with 1 posts (0 thanks)
looks_4
Xav1029
with 1 posts (2 thanks)
trending_up
3,617 views
thumb_up
11 thanks given
group
4 followers
forum
6 posts
attach_file
2 attachments
Add Control to Chart - vvhg needs coding help
November 25th, 2012, 02:30 PM
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
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
November 25th, 2012, 02:37 PM
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.
November 25th, 2012, 03:04 PM
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
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
June 2nd, 2015, 04:09 AM
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
June 2nd, 2015, 05:43 AM
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
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 ! ! !
July 21st, 2015, 12:33 PM
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
Can you post an image of the result?
Hello
yes here is an image of the result. sorry it took a while
Last Updated on July 21, 2015