Split Graphic into pieces c#
<p>My Code:</p>

<pre><code>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;
using TouchlessLib;

namespace WebCam2
{
    public partial class Form1 : Form
    {
        TouchlessMgr ngr = new TouchlessMgr();
        Bitmap _overlay;
        public Form1()
        {
            InitializeComponent();
            foreach (Camera c in ngr.Cameras)
            {
                listBox1.Items.Add(c);
                listBox1.SelectedValueChanged += new EventHandler(listBox1_SelectedValueChanged);

            }
        }

        void listBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            ngr.CurrentCamera = (Camera) listBox1.SelectedItem;
            ngr.CurrentCamera.OnImageCaptured += c_OnImageCaptured;
        }

        void c_OnImageCaptured(object sender, CameraEventArgs e)
        {
            pictureBox1.Image = ngr.CurrentCamera.GetCurrentImage();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {


        }

        public EventHandler&lt;CameraEventArgs&gt; cam_OnImageCaptured { get; set; }

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            List &lt;Graphics&gt; list = new List &lt;Graphics&gt;();
            ngr.RefreshCameraList();
            Graphics g = Graphics.FromImage(pictureBox1.Image);
            Brush redBrush = new SolidBrush(Color.Red);
            Pen pen = new Pen(redBrush,3);
            for ( int i = 0; i &lt; pictureBox1.Width; i = (pictureBox1.Width/3)+i)
            {
                for (int y = 0; y &lt; pictureBox1.Height; y = (pictureBox1.Height / 3) + y)
                {
                    g.DrawRectangle(pen, i, y, pictureBox1.Width / 3, pictureBox1.Height / 3);
                }
            }
            g.Dispose();


        }

    }
}
</code></pre>

<p>This code works only sometimes not everytime, i dont know whats wrong with the code.
I also want to split the image into a 3x3 matrix but i do not know how.</p>

<p>Please help!</p>

<p>Output(1st Time no frame,2nd time right):</p>

<p>ImageLink:</p>

<p><a href="http://www.imagebanana.com/view/4j58i05z/Unbenannt2.png" rel="nofollow">http://www.imagebanana.com/view/4j58i05z/Unbenannt2.png</a></p>
