omnimny 0 Newbie Poster

Hello everybody,

here attached two code project for a form (the first) with drawing a grid as squared paper chart , acting on the scrolls (vert or horiz) the squared paper chart redraws itself in the correct way. Please Help me. Thank you.

1st project:

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;

namespace GrandShaper
{
    public partial class Form1 : Form
    {
            private Pen bluePen = new Pen(Color.Blue, 3);
            private Pen redPen = new Pen(Color.Red, 2);
            private Brush SolidAzureBrush = Brushes.Azure;

            protected override void OnPaint(PaintEventArgs e)
            {
                // define when scrolls appears
                base.OnPaint(e);
                Graphics dc = e.Graphics;
                Point scrollOffset = this.AutoScrollPosition;
                dc.TranslateTransform(scrollOffset.X, scrollOffset.Y);
                if (e.ClipRectangle.Top + scrollOffset.X < 3000 ||
                    e.ClipRectangle.Left + scrollOffset.Y < 3000)
                {

                }
                //squared paper chart
            // Get the graphics object
            Graphics gfx = e.Graphics;
            // Create a new pen that we shall use for drawing the line
            Pen myPen = new Pen(Color.PaleGoldenrod);
            Pen myBPen = new Pen(Color.Goldenrod);
            // Loop and create a horizontal line 10 pixels below the last one
            for (int i = 0; i <= 3000; i = i + 10)
            {
                gfx.DrawLine(myPen, 0, i, 3000, i);
            }
            // Loop and create a vertical line 10 pixels next to the last one
            for (int x = 0; x < 3000; x = x + 10)
            {
                gfx.DrawLine(myPen, x, 0, x, 3000);

            }
            // Loop and create horizontal line 40 pixels next to the last one
            for (int z = 0; z < 3000; z = z + 40)
            {
                gfx.DrawLine(myBPen, 0, z, 3000, z);
            }

            // Loop and create a vertical line 40 pixels next to the last one
            for (int zz = 0; zz < 3000; zz = zz + 40)
            {
                gfx.DrawLine(myBPen, zz, 0, zz, 3000);
            }

        }



            public Form1()
            {
                InitializeComponent();

                //
                // Required for Windows Form Designer support
                //
                InitializeComponent();
                this.BackColor = Color.White;
                this.Size = new System.Drawing.Size(980, 600);
                this.Text = "Scroll Shapes Correct";
                this.AutoScrollMinSize = new Size(3000, 2000);
            }

            private void Form1_Load(object sender, EventArgs e)
            {

            }

            //
            // TODO: Add any constructor code after InitializeComponent call
            //

        }

} 

Here follows the 2nd project: here I try to do the same squared paper chart in a panel, but acting on the arrow of the scrolls it doesn't redraw in the correct way:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;

namespace DrawingGrid2
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();

        }

        protected void panel1_Paint(object sender, PaintEventArgs e)
        {
             {

            // square paper chart
            // Get the graphics object
            Graphics gfx = e.Graphics;
            // Create a new pen that we shall use for drawing the line
            Pen myPen = new Pen(Color.PaleGoldenrod);
            Pen myBPen = new Pen(Color.Goldenrod);
            // Loop and create a horizontal line 10 pixels below the last one
            for (int i = 0; i <= 3000; i = i + 10)
            {
                gfx.DrawLine(myPen, 0, i, 2990, i);
            }
            // Loop and create a vertical line 10 pixels next to the last one
            for (int x = 0; x < 3000; x = x + 10)
            {
                gfx.DrawLine(myPen, x, 0, x, 2990);

            }
            // Loop and create horizontal line 40 pixels next to the last one
            for (int z = 0; z < 3000; z = z + 40)
            {
                gfx.DrawLine(myBPen, 0, z, 2950, z);
            }

            // Loop and create a vertical line 40 pixels next to the last one
            for (int zz = 0; zz < 3000; zz = zz + 40)
            {
                gfx.DrawLine(myBPen, zz, 0, zz, 2950);
            }

        }


        // Close
        private void esciToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }

    }
}