Changing height of toolbar - how?  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Changing height of toolbar - how?

Postby JoshM » 03 Aug 2012

If I apply the default Chart toolbar example on my chart, it looks like this:

Image

How can make the toolbar higher? I've tried the AutoSize = False and Height = x from the ToolStrip class (as suggested by the documentation), but these values don't change the height of the toolbar. What am I missing? :)

Code:

Code: Select all

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace PowerLanguage.Indicator{

public class Chart_Toolbar_Test : IndicatorObject {
public Chart_Toolbar_Test(object _ctx):base(_ctx){}

protected override void Create(){
Length = 20;
m_adx = AddPlot(new PlotAttributes("Avg"));

}

private IPlotObject m_adx;

private int Length { get; set; }

private void AddItem2ToolStrip(ToolStrip tb, ToolStripItem item){
item.Tag = this;
tb.Items.Add(item);
}

private bool tool_bar_inited = false;
protected override void StartCalc()
{
if (!tool_bar_inited){
tool_bar_inited = true;
ChartToolBar.AccessToolBar(tb=>
{
var _tsi3 = new ToolStripButton {Text = "plot color"};
set_color_tsi(_tsi3, m_plot_color);
_tsi3.Click += button1_Click;
AddItem2ToolStrip(tb, _tsi3);


var _track = new TrackBar
{
Dock = DockStyle.Fill,
Maximum = 1000,
Minimum = 10,
SmallChange = 10,
Value = Length,
Text = "Average Length"
};
_track.ValueChanged += _new_track;
AddItem2ToolStrip(tb, new ToolStripControlHost(_track));

AddItem2ToolStrip(tb, new ToolStripSeparator());

// Set all autosizes to false and adjust height
tb.AutoSize = false;
_track.AutoSize = false;
_tsi3.AutoSize = false;

_track.Height = 200;
_tsi3.Height = 250;
tb.Height = 750;
});

}


}

private void _new_track(object sender, EventArgs e)
{
var _tsi = (TrackBar) sender;
if (Length != _tsi.Value)
{
Length = _tsi.Value;
ExecControl.Recalculate();
}
}

private Color m_plot_color = Color.Red;

private static void set_color_tsi(ToolStripButton _tsi, Color _clr){
var _bmp = new Bitmap(50, _tsi.Height);
var _gr = Graphics.FromImage(_bmp);
_gr.FillRectangle(new SolidBrush(_clr), new Rectangle(new Point(0), _bmp.Size));
_tsi.Image = _bmp;
}

private void button1_Click(object sender, EventArgs e)
{
var _tbi = (ToolStripButton) sender;
var MyDialog = new ColorDialog {Color = m_plot_color};
if (MyDialog.ShowDialog() == DialogResult.OK)
{
m_plot_color = MyDialog.Color;
set_color_tsi(_tbi, MyDialog.Color );
ExecControl.Recalculate();
}
}

protected override void CalcBar(){
m_adx.Set( PublicFunctions.Average(Bars.Close, Length), m_plot_color );
}

protected override void Destroy(){
if (tool_bar_inited)
{
ChartToolBar.AccessToolBar(tb =>
{
var _for_erase = new List<ToolStripItem>();

foreach (ToolStripItem item in tb.Items)
if (ReferenceEquals(this, item.Tag))
_for_erase.Add(item);

foreach (var item in _for_erase)
tb.Items.Remove(item);
});
}
}
}
}


I've added these lines to the example code (in the StartCalc method):

Code: Select all

// Set all autosizes to false and adjust height
tb.AutoSize = false;
_track.AutoSize = false;
_tsi3.AutoSize = false;

_track.Height = 200;
_tsi3.Height = 250;
tb.Height = 750;
Attachments
scr.03-08-2012 17.59.24.png
(4.16 KiB) Downloaded 1293 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Changing height of toolbar - how?

Postby Henry MultiСharts » 06 Aug 2012

Hello Josh,

Our engineers are analyzing this behavior.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Changing height of toolbar - how?  [SOLVED]

Postby Henry MultiСharts » 07 Aug 2012

Josh, please check the code with the fix in the attachment.
The fix is in 1 additional line:

Code: Select all

tb.Dock = DockStyle.Top;
Attachments
CBT_Fix.pln
(1.97 KiB) Downloaded 820 times

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Changing height of toolbar - how?

Postby JoshM » 07 Aug 2012

Awesome, thanks! Also, nice that with the tb.Dock setting to DockStyle.Bottom the toolbar can be placed in the bottom.

These toolbar possibilities are quite great. :)


Return to “MultiCharts .NET”