Page 1 of 1

Drag and drop axes, having an issue

Posted: Wed Dec 12, 2007 9:58 pm
by 14046227
In the next version of our software, we would like to allow the user to drag and drop axis around. I am in the beginning stages of coding this feature, and I have already run in to an issue:

I can use Axis.Clicked(x, y) to see if a mouse click is inside the axis, but this only checks the tiny area where the ticks are. How do I get the rectangle that encompasses the entire axis area, including the labels and titles? I wonder the user to be able to drag from anywhere in that area, not just the ticks. AxisTitle has no Clicked method, and in fact it's Top, Left, Width and Height properties are always 0 (so I can't even created the rect for myself).

Is there a way to work around? Or a way to get the complete axis rect, including the titles and labels?

Posted: Thu Dec 13, 2007 11:15 am
by narcis
Hi MattHolmes,

In that case you can try combining properties shown in the code snippet below. For labels's width you can use MaxLabelsWidth and for title's dimensions you could use its Font.Size or even ChartRect's bounds.

Code: Select all

		private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
		{
			listBox1.Items.Clear();

			listBox1.Items.Add("tChart1.Axes.Left");
			listBox1.Items.Add("IStartPos: " + tChart1.Axes.Left.IStartPos);
			listBox1.Items.Add("IEndPos: " + tChart1.Axes.Left.IEndPos);
			listBox1.Items.Add("MaxLabelsWidth: " + tChart1.Axes.Left.MaxLabelsWidth());
			listBox1.Items.Add("Title.Font.Size: " + tChart1.Axes.Left.Title.Font.Size);
			listBox1.Items.Add("tChart1.Chart.ChartRect.Left: " + tChart1.Chart.ChartRect.Left);
		}

Posted: Thu Dec 13, 2007 5:46 pm
by 14046227
Hello,

I actually figured this out yeterday. This is what I did, which works perfect:

Code: Select all

                Graphics g = this.CreateGraphics ();
                SizeF size = g.MeasureString (axis.Title.Caption, axis.Title.Font.DrawingFont);
                int width = axis.MaxLabelsWidth ();
                width += (int)Math.Ceiling (size.Height);

                Rectangle rect = axis.AxisRect ();
                rect.Offset ((axis.OtherSide ? 0 : -width), 0);
                rect.Width += width;