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
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