How to make DrawString work for negative y scale factor?

51 views Asked by At

Working on a private stock chart where I use a rendering rectangle with an origin at lower left and inverted y axis, scale factor y is negative. Y axis ticks render nicely but drawing text (drawstring) is where I run into problems.

            using (Pen pen = new Pen(_color))
            using (Font drawFont = new Font("Arial", 16))
            using (SolidBrush drawBrush = new SolidBrush(Color.Black))
            {
                pen.Width = 1F / e.Graphics.DpiX;
                foreach (float tick in this.TimeSeriesPanelControl.YTicks)
                {
                    e.Graphics.DrawLine(pen, right, tick, right + 10, tick);
                    // this is not producing text to the right of the tick that renders properly.
                    e.Graphics.DrawString(tick.ToString("F2"), drawFont, drawBrush, right + 15, tick);
                }
            }

I have seen that the text is upside down caused by the negative scale factor on the y coordinate.

The question is how to make drawstring render the text to the right of the tick?

0

There are 0 answers