Page 1 of 1

How can I find the location and size of an axis title?

Posted: Tue Aug 19, 2008 9:29 pm
by 8739068
I am wanting to place a combobox over the Axis title of the bottom axis of a simple 2D, X-Y chart. I can easily create the combobox, but locating the combobox over the bottom axis title location, has proven to be difficult because the Axis.Title member does not seem to update Left and Top properties.

Is there a way I can get access that that information? I have the source code so if needed I could modify our version of the source to meet our needs.

Posted: Wed Aug 20, 2008 11:36 am
by Pep
Hello Mike,

you can know where the bottom axis title is placed using :

Code: Select all

    private void button1_Click(object sender, EventArgs e)
      String text = "XXXXXXX";
      int twidth = (int) tChart1.Graphics3D.TextWidth(text) / 2;
      int xpos = tChart1.Axes.Bottom.IStartPos + (tChart1.Axes.Bottom.IAxisSize / 2) - twidth;
      int ypos = tChart1.Axes.Bottom.Position + tChart1.Axes.Bottom.Labels.Height + tChart1.Axes.Bottom.Ticks.Length +
      tChart1.Graphics3D.TextOut(xpos, ypos, text);

That works!!!

Posted: Wed Aug 20, 2008 3:32 pm
by 8739068
That worked perfectly. Thanks!

Almost perfect

Posted: Tue Dec 30, 2008 8:16 pm
by 8739068
I have a small problem. When the Chart is resized the position of my combobox is sometimes off and othertimes it is perfect.

i have a method called SetLocation() where I use the code you suggested to set the position of my combobox. I then have tried various events to call the SetLocation method.

I have tried tchart.Layout, tchart.Resize

Both of these events seem to fire inconsistently or the axis label reports bad position values. About half the time the combobox will not move after I have done something to resize the chart.

Is there another event that would work more consistently?
Is it possible to put an event on the Axis label itself ( I could modify my copy of the source to do this)?

Posted: Fri Jan 02, 2009 3:10 pm
by Pep
Hi Mike,

have you tried to use the OnAfterDraw event ?
About the axis labels, you have the OnGetAxisLabel event which allows to modify the axis labels before to draw, each time that have to be displayed.