Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8268983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:04:22+00:00 2026-06-08T06:04:22+00:00

public void SaveFormPicutreBoxToBitMapIncludingDrawings() { using (Bitmap b = new Bitmap(pictureBox1.Width, pictureBox1.Height)) { pictureBox1.DrawToBitmap(b, new

  • 0
public void SaveFormPicutreBoxToBitMapIncludingDrawings()
{
    using (Bitmap b = new Bitmap(pictureBox1.Width, pictureBox1.Height))
    {
        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"); // to fix/repair give gdi error exception.
            PbToBitmap++;
        }
    } 
}

If I move the trackBar to the right it will save the first file 000000.bmp then raise it by one next time it will save file 000001.bmp

But if I move back to the left once now the variable fn is 000002.bmp which doesn’t exist and it will save the previous image which is really 000001.bmp.

What it suppose to do when I move to the left back it should be 000001.bmp see that it exist and do nothing.

If will not make this checking it will just keep saving files all the time if i move the trackBar to the right or to the left so after few times i will have more then 90 files which are almost all the same.

How can I solve it?

The variable PbtoBitmap is type of int in the top of Form1 I just started it with 0.
PbToBitmap = 0;

The trackBar I’m talking about is trackBar1 where in the scroll event I’m calling this SaveFormPicutreBoxToBitMapIncludingDrawings function .

This is the trackBar1 scroll event:

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

    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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T06:04:23+00:00Added an answer on June 8, 2026 at 6:04 am

    It is not clear what you are trying to accomplish, but you are generating file names from a counter PbToBitmap. This counter only increases and never decreases so of course it will “just keep saving files… “.

    If you want the counter to match the frame you’re on, get rid of PbToBitmap and inside trackBar1_Scroll call:

    string dir = @"d:\PictureBoxToBitmap";
    SaveFormPictureBoxToBitMapIncludingDrawings(dir, currentFrameIndex);
    

    Change your SaveFormPictureBoxToBitMapIncludingDrawings to:

    public void SaveFormPictureBoxToBitMapIncludingDrawings(string dir, int frameIndex)
    {
        string fn = Path.Combine(dir, frameIndex.ToString("D6") + ".bmp");
        if (!File.Exists(fn))
        {
            using (Bitmap b = new Bitmap(pictureBox1.Width, pictureBox1.Height))
            {
                pictureBox1.DrawToBitmap(b, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
                b.Save(fn);
            }
        } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public void EditAndSave(String fileName) { Bitmap b = new Bitmap(fileName); /** * Edit bitmap
public void ReplyMessage(string subject, string body, string to) { EmailMessage message = new EmailMessage(service);
public void populateNotesFromFile() { try{ BufferedReader reader = new BufferedReader(new FileReader(DEFAULT_NOTES_SAVED)); String fileNotes =
public void Foo (IEnumerable<object> objects) { } var strings = new List<string>{first, second, third};
public void thisisnotworking() { Scanner input=new Scanner(System.in); String cardA; String cardB; System.out.print(Enter Card: );
public void SomeMethod1() { using (TemplateEntities ctx = new TemplateEntities()) { //do something in
public void openOptions() { Intent intent=new Intent(this,Game.class); //intent.putExtra(razmer, level); startActivity(intent); // Intent intent=new Intent(this,Options.class);
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Init(); backthread tr=new backthread(); tr.execute(0,0,0); } backthread
public void GrabData() throws IOException { try { BufferedReader br = new BufferedReader(new FileReader(data/500.txt));
public void valueChanged(TreeSelectionEvent event) { //Add images depending on selection. String selection = navigation.getLastSelectedPathComponent().toString();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.