flip coordinates when drawing to control

前端 未结 5 506
深忆病人
深忆病人 2020-12-06 06:05

I am drawing a graph on a control, but 0,0 is at the top-left hand corner of the control. Is there a way to flip the coordinates so that 0,0 is at the lower left corner of t

5条回答
  •  忘掉有多难
    2020-12-06 06:27

    Here's a simple UserControl that demonstrates how to do this:

    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
    
            InitializeComponent();
        }
    
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.ScaleTransform(1.0F, -1.0F);
            e.Graphics.TranslateTransform(0.0F, -(float)Height);
            e.Graphics.DrawLine(Pens.Black, new Point(0, 0), new Point(Width, Height));
    
            base.OnPaint(e);
        }
    }
    

提交回复
热议问题