How to draw a scrollable form with a bottom-left origin using GDI+ ??

J

johannblake

I want to create a scrollable window using GDI+ where the origin is
located in the bottom-left corner rather than the default top-left
corner.

Currently I have found several examples on how to scroll the window and
even how to set the drawing origin at the bottom-left corner. What I
have not been able to accomplish is doing both of these simultaneously.
I cannot find any code examples that show how this is done. When I
attempt it, everything drawn is badly messed up.

Here is my sample code. What's wrong or missing?

private void Form1_Load(object sender, System.EventArgs e)
{
this.BackColor = Color.Aqua;
this.AutoScrollMinSize = new Size(250,350);
}

protected override void OnPaint( PaintEventArgs e )
{
Graphics dc = e.Graphics;

// The following lines of code that are comment out are suppose to move
// the origin to the bottom-left corner.
// Matrix matrix = new Matrix(1, 0, 0, -1, 0, 0);
// dc.Transform = matrix;
// dc.ScaleTransform(1, 1, MatrixOrder.Append);

dc.TranslateTransform(this.AutoScrollPosition.X,
this.AutoScrollPosition.Y);

Pen redPen = new Pen(Color.Red, 2);
dc.DrawLine(redPen, 30,30,100,100);
}


Thanks for any help
Johann Blake
 
J

johannblake

I forgot to mention that when the origin is in the bottom-left corner,
the values of Y must increase from bottom to top.
 

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