Moving the drawing origin to the bottom left corner

P

Polaris431

I have spent hours through newsgroups and googling but I am at a loss
how to move the drawing origin from the top left corner to the bottom
left corner and have Y values increase towards the top.

All the stuff I find shows stuff like this:

private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen pen = new Pen(Color.Blue);

Matrix mm = new Matrix();
mm = new Matrix(1, 0, 0, -1, 0, 0);
g.Transform = mm;

g.DrawLine(pen, 0, 0, 100, 100);
}

But nothing gets drawn. What am I missing?

Thanks
Johann
 
P

Polaris431

Finally figured out the problem. Needed to add the following after the
line with g.Transform

g.TranslateTransform(0, this.ClientRectangle.Height,
MatrixOrder.Append );
 
J

Jonas Hallgren

Finally figured out the problem. Needed to add the following after the
line with g.Transform

g.TranslateTransform(0, this.ClientRectangle.Height,
MatrixOrder.Append );


And if you study the Matrix method carefully you will see that the
last zero actually is a "float dy" value. Which corresponds to the
TranslateTransform. Like so:

private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen pen = new Pen(Color.Blue);

Matrix mm = new Matrix();
mm = new Matrix(1, 0, 0, -1, 0, this.ClientRectangle.Height);
g.Transform = mm;

g.DrawLine(pen, 0, 0, 100, 100);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top