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 8765959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:25:33+00:00 2026-06-13T16:25:33+00:00

Few days ago I’ve started working on my own photo viewer/editor. I’ve implemented method

  • 0

Few days ago I’ve started working on my own photo viewer/editor. I’ve implemented method “OnKeyDown” which changes photos depending of which arrow key is pressed:

case Keys.Left:
            case Keys.Down:
                ic.getImage().Dispose();
                --fileIndex;
                if (fileIndex < 0)
                    fileIndex = (fileCount - 1);
                ic.setImage(Image.FromFile(fileNames[fileIndex]), ref pictureBox1);
            break;

            case Keys.Right:
            case Keys.Up:
                ic.getImage().Dispose();
                ++fileIndex;
                fileIndex %= fileCount;
                ic.setImage(Image.FromFile(fileNames[fileIndex]), ref pictureBox1);
            break;

This works perfectly. Next thing I wanted to do is to program the slideshow, so I used System.Timers.Timer to trigger the event goRight() which executes the same code as if right arrow key is pressed:

public void goRight(object source, ElapsedEventArgs e)
    {
            ic.getImage().Dispose();
            ++fileIndex;
            fileIndex %= fileCount;
            ic.setImage(Image.FromFile(fileNames[fileIndex]), ref pictureBox1);
    }

When using slideshow app just breaks. I can’t figure out why, because the code is exactly the same. If I comment out the ic.getImage().Dispose() slideshow works but the amount of data in RAM goes higher and higher with each next photo.

Am I doing something wrong? Thank you for your time, I appreciate it!

Uh, I almost forgot. Is there a way to make indexes go backwards without if statement (in key down and key left events) (like operator % for forwards). I did try this:

++fileIndex;
fileIndex %= fileCount;
ic.setImage(Image.FromFile(fileNames[(fileCount -1) - fileIndex]), ref pictureBox1);

And it works well if I go in just one direction, but if I change direction it skips few indexes. Any thoughts about that?

Best regards. Z

  • 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-13T16:25:34+00:00Added an answer on June 13, 2026 at 4:25 pm

    For the indexes you could do something like:

    fileIndex = (fileIndex == 0) ? fileCount -1 : fileIndex - 1; // decrementing
    
    fileIndex = (fileIndex == fileCount - 1) ? 0 : fileIndex + 1; // incrementing
    

    and as cHao says, use System.Windows.Forms.Timer instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started a new app a few days ago and began working with
A few days ago, I started working with cocos2d. I really like the framework.
Few days ago Membase started working very slow. We are using local moxi proxy
Few days ago all was ok: when I started my web-site with Silverlight 4.0
Few days ago I started experimenting with Mercurial, and everything went great, until I
A few days ago i asked this question: Displaying images from Facebook photo albums
A few days ago I started with Ubuntu for the first time. I want
A few days ago, I watched the video tutorial which explains how to use
A few days ago the push notification for Android devices was working fine because
I started with PHP a few days ago. I made some querys to my

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.