Hey there! Sign in to join this conversationNew here? Join for free
x Turn on thread page Beta
    • Thread Starter

    here is the code i'm using:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    namespace P1
        public partial class Form1 : Form
            private float mLastFactor;
            private Bitmap mBuffer;
            private float mFactor = 0.4F;
            public Form1()
            private void Form1_Load(object sender, EventArgs e)
            private void Form1_Paint(object sender, PaintEventArgs e)
                if (mBuffer == null || Math.Abs(mFactor - mLastFactor) > 1E-6 ||
                    mBuffer.Width != this.ClientSize.Width || mBuffer.Height != this.ClientSize.Height)
                    if (mBuffer != null) mBuffer.Dispose();
                    mLastFactor = mFactor;
                    mBuffer = new Bitmap(this.ClientSize.Width, this.ClientSize.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
                    using (Graphics bg = Graphics.FromImage(mBuffer))
                        Graphics gfx = this.CreateGraphics();
                        Pen myPen = new Pen(Color.Gray, 1);
                        gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                        for (int i = 0; i < this.ClientSize.Width; i += 30)
                            gfx.DrawLine(myPen, i, 0, i, this.ClientSize.Height);
                        for (int i = 0; i < this.ClientSize.Height; i += 30)
                            gfx.DrawLine(myPen, 0, i, this.ClientSize.Width, i);
                e.Graphics.DrawImage(mBuffer, 0, 0);
    it does the job, but does it very slowly. is there a faster, more efficient way to draw a grid on a form?
Have you ever experienced racism/sexism at uni?
Useful resources

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.