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

  • Home
  • SEARCH
  • 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 6378011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:56:56+00:00 2026-05-25T01:56:56+00:00

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

  • 0
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 d3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            pictureBox1.Image = Image.FromFile("C:\\Users\\ocean\\Desktop\\deneme.png");
            pictureBox1.Location = new Point(0, 0);
            pictureBox2.Image = Image.FromFile("C:\\Users\\ocean\\Desktop\\pul1.png");
        }

        protected override void OnMouseClick(MouseEventArgs e)
        {
            Graphics theGraphics = Graphics.FromHwnd(this.Handle);

            for (int i = 0; i < 200; i += 5)
            {
                pictureBox2.Location = new Point(i, 100);
                theGraphics.Flush();

                System.Threading.Thread.Sleep(50);
                pictureBox2.Invalidate();
            }           
        }
    }
}

In this code picturebox2 is moving ok but previous locations image stay ON THEuntil the loop finishes. When loop finished the older parts would be erased. I dont want the previous paintings inside the loop I just want to move on pictureBox1. Im new at C# so please help me:) In J2Me I was using flushgraphics but here I tried and it did not work and If you can give an example I would be happy .

  • 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-05-25T01:56:57+00:00Added an answer on May 25, 2026 at 1:56 am

    In C#, just as in Swing, if you are on the UI or event thread, nothing that you change will be noticed by the user until you are done.

    So, if you want to move these, your best bet is to start by getting off the UI thread, by starting a new thread, and then go through your loop.

    But, the problem is that you will need to be on the UI thread to make the changes.

    This is why your sleep didn’t work, you are just putting the event thread to sleep, btw.

    Which version of C# are you using? There are many options on creating a thread, and on working with the UI thread.

    Here is a link to creating a thread:
    http://msdn.microsoft.com/en-us/library/7a2f3ay4(v=vs.80).aspx

    Here is a way to deal with how to get back to the UI thread:

    http://blogs.msdn.com/b/csharpfaq/archive/2004/03/17/91685.aspx.

    For example, to create a thread you can do this, which came from http://www.rvenables.com/2009/01/threading-tips-and-tricks/

    I do my threads this way as I find it simpler to see what is happening.

     (new Thread(() => {
            DoLongRunningWork();
            MessageBox.Show("Long Running Work Finished!");
        }) { Name = "Long Running Work Thread",
            Priority = ThreadPriority.BelowNormal }).Start();
    

    The most complete answer on how to do your update on the UI thread would be this question:

    How to update the GUI from another thread in C#?

    UPDATE:

    For the part where it states to do long running work, you can add this before the thread block:

    TaskScheduler uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
    

    Then you can do this inside your thread:

    (new Task(() =>
        {
            //copy pixel
            pictureBox2.Invalidate();  // You may want to just invalidate a small block                 around the pixel being changed, or every some number of changes.
        }))
    .Start(uiScheduler);
    

    By making these changes you could simplify making the change you want, but some of this may be more complex than what you want, which is why I gave some other links to give more information. But, for more on using Task you can look at this excellent blog:

    http://reedcopsey.com/2010/03/18/parallelism-in-net-part-15-making-tasks-run-the-taskscheduler/

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

Sidebar

Related Questions

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace GenericCount { class Program {
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; namespace ConsoleApplication1 { public
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace EfTestFactory { public abstract class
My Code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq;
This C#/WPF code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using
here's the code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using

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.