How can I identify to which direction I am moving the bar of the trackBar in the scroll event?
<p>This is the scroll event:</p>

<pre><code>private void trackBar1_Scroll(object sender, EventArgs e)
{
    currentFrameIndex = trackBar1.Value;
    textBox1.Text = "Frame Number : " + trackBar1.Value;
    wireObject1.woc.Set(wireObjectAnimation1.GetFrame(currentFrameIndex)); 
    // LoadPictureAt(trackBar1.Value, sender);

    trackBar1.Minimum = 0;
    trackBar1.Maximum = fi.Length - 1;
    setpicture(trackBar1.Value);
    pictureBox1.Refresh();

    button1.Enabled = false;
    button2.Enabled = false;
    button3.Enabled = false;
    button4.Enabled = false;
    button8.Enabled = false;
    SaveFormPicutreBoxToBitMapIncludingDrawings();
    return; 
}
</code></pre>

<p>Now inside the scroll event im calling the function: <code>SaveFormPicutreBoxToBitMapIncludingDrawings()</code>. This is the function:</p>

<pre><code>public void SaveFormPicutreBoxToBitMapIncludingDrawings()
{
    using (Bitmap b = new Bitmap(pictureBox1.Width, pictureBox1.Height))
    {
        PbToBitmap++;
        pictureBox1.DrawToBitmap(b, 
            new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
        b.Save(@"d:\PictureBoxToBitmap\" + PbToBitmap.ToString("D6")  + ".bmp");
    } 
}
</code></pre>

<p>Each time I am moving the trackBar to the right it will save a new image of the current frame I am on now. But the prbolem is, when I I am moving to the left back after few times I am getting exception GDI error. I think it happen since its trying to save again on files that already exists.</p>

<p>So I want to make somehow that if I move the scroll bar to the left dont call the function.</p>

<hr>

<p>Tried to solve it by checking if the file/s allready exists on the hard disk so i added a checking inside the function:</p>

<pre><code>public void SaveFormPicutreBoxToBitMapIncludingDrawings()
        {
            using (Bitmap b = new Bitmap(pictureBox1.Width, pictureBox1.Height))
            {
                PbToBitmap++;
                pictureBox1.DrawToBitmap(b, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
                string fn = @"d:\PictureBoxToBitmap\" + PbToBitmap.ToString("D6") + ".bmp";
                if (File.Exists(fn))
                {
                }
                else
                {
                    b.Save(@"d:\PictureBoxToBitmap\" + PbToBitmap.ToString("D6") + ".bmp");
                }
            } 
        }
</code></pre>

<p>So i used a breakpoint on the IF and deleted all files from hard disk. Then once i moved the trackBar to the right i got rightaway an exception:</p>

<p>External exception:</p>

<p>A generic error occurred in GDI+.</p>

<pre><code>System.Runtime.InteropServices.ExternalException was unhandled
  Message=A generic error occurred in GDI+.
  Source=System.Drawing
  ErrorCode=-2147467259
  StackTrace:
       at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
       at System.Drawing.Image.Save(String filename, ImageFormat format)
       at System.Drawing.Image.Save(String filename)
       at AnimationEditor.Form1.SaveFormPicutreBoxToBitMapIncludingDrawings() in D:\C-Sharp\AnimationEditor\AnimationEditor\Form1.cs:line 746
       at AnimationEditor.Form1.trackBar1_Scroll(Object sender, EventArgs e) in D:\C-Sharp\AnimationEditor\AnimationEditor\Form1.cs:line 547
       at System.Windows.Forms.TrackBar.OnScroll(EventArgs e)
       at System.Windows.Forms.TrackBar.WndProc(Message&amp; m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message&amp; m)
       at System.Windows.Forms.Control.WndProc(Message&amp; m)
       at System.Windows.Forms.ScrollableControl.WmHScroll(Message&amp; m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message&amp; m)
       at System.Windows.Forms.Form.WndProc(Message&amp; m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at System.Windows.Forms.NativeWindow.DefWndProc(Message&amp; m)
       at System.Windows.Forms.Control.DefWndProc(Message&amp; m)
       at System.Windows.Forms.Control.WndProc(Message&amp; m)
       at System.Windows.Forms.TrackBar.WndProc(Message&amp; m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at AnimationEditor.Program.Main() in D:\C-Sharp\AnimationEditor\AnimationEditor\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
</code></pre>

<hr>

<p>And the pictureBox have an image inside and on the image there are points drawings so i dont think its something with null.</p>
