Page 1 of 1

LegendScrollBar as required

Posted: Tue Mar 10, 2009 3:51 am
by 15049432
Is there a way to only display a LegendScrollBar tool if it is needed?

I mean, can I detect if the number of series' I have can't be displayed in the legend and in that case, add the scroll bar?

Posted: Tue Mar 10, 2009 9:26 am
by yeray
Hi LVL,

You could compare the height of the legend with the legend height that X series need to be shown without scrollbar and activate or deactivate it:

Code: Select all

Private Sub TChart1_OnGetLegendRect(Left As Long, Top As Long, Right As Long, Bottom As Long)
  legendHeight = Bottom - Top
  wishedHeight = TChart1.Series(0).Count * 14

  If legendHeight < wishedHeight Then
    TChart1.Tools.Items(0).Active = True
  Else
    TChart1.Tools.Items(0).Active = False
  End If
End Sub

Thanks!

Posted: Tue Mar 10, 2009 7:52 pm
by 15049432
Thanks Yeray - I actually studied the object model a bit more and solved it like this:

Code: Select all

int nNumInLegend = m_Chart.GetLegend().GetLastValue() - m_Chart.GetLegend().GetFirstValue();

if (nNumInLegend < m_nNumSeries)
{
...