Setting 'System.Drawing.Graphics.Transform' in Form.OnPaint yields ArgumentException

287 Views Asked by At

System.ArgumentException: 'Parameter is not valid.'

This is the first time I have tried to toy with a Matrix and transformations. Anywho...

protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.Transform = m_Vars.TransformMatrix;
            g.Clear (m_Vars.ClearColor);

            g.FillRectangle (m_Vars.FillBrush , m_Vars.DrawRectangle);
            g.DrawRectangle (m_Vars.LinePen , m_Vars.DrawRectangle);

            if (m_Vars.DrawCrossSection)
            {
                g.DrawLine (m_Vars.LinePen , m_Vars.DrawRectangle_TopMidpoint , m_Vars.DrawRectangle_BottomMidpoint);
                g.DrawLine (m_Vars.LinePen , m_Vars.DrawRectangle_LeftMidpoint , m_Vars.DrawRectangle_RightMidpoint);
            }

            Invalidate ();
        }

Exception is thrown at "g.Transform = m_Vars.TransformMatrix". Locals reveals my desired -new- matrix has 6 values: 0.1, 0.0 0.0, 0.0 0.0, 0.0

-- When I create this replacement transform matrix, I use "new Matrix()' which creates an identity matrix.

Is my new matrix the issue or is System.Drawing the issue? Also, any kind of work around perhaps?

0

There are 0 best solutions below