CAN ANYBODY HELP ME.............
see i've created a label and a pictureBox..............in the below code when i press the key "A" the count begins which is been displayed in the label........and also during when pressing ("A"), the picture "RedSlideButton.png" is displayed within the pictureBox , and on releasing ("A") the picture("RedSlideButton.png") disappears and the picture "GraySlideButton.png" appears.........but the problem is that when i press the key the count is displayed correctly with the pressing action.......but the picture IS displayed with a little bit delay........for a instant key press even the "RedSlideButton.png" is not even displayed.............

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Linq;
using System.Text;
using System.Threading;
using System.Runtime.InteropServices;
namespace MultipleKeys
{
    public partial class MainForm : Form
    {
        int s = 0;
        public MainForm()
        {
            InitializeComponent();
        }
        private void MainFormKeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.A)
            {
                SetPictureBoxSizeMode2();
            }
        }
        private void MainFormKeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.A)
            {
                s++;
                SetCount(s);
                SetPictureBoxSizeMode1();
            }
            if (e.KeyCode == Keys.B)
            {
                s--;
                SetCount(s);
            }
        }
        private void SetPictureBoxSizeMode1()
        {
            string path = @"G:\RedSlideButton.png";  // Change the path if needed.

            pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
            pictureBox1.Image = Image.FromFile(path);
        }
        private void SetPictureBoxSizeMode2()
        {
            string path = @"G:\GraySlideButton.png";  // Change the path if needed.

            pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
            pictureBox1.Image = Image.FromFile(path);
        }
        public void SetCount(int s)
        {   
                    label1.Text = "" +s;
                    label1.Refresh();
                    Thread.Sleep(250);
        }
    }
}

Hi!

what happen when you removed this line:

Thread.Sleep(250);

when i remove Thread.Sleep(250); it works perfectly..............but i want that thread to slow down the counting speed..........

If I understood correctly, you want label to be update after some delay when key pressed. Right ???

For that you should use "Timer" component and set the label on Timer_Tick event. Use enable property to control the timer and set appropriate delay for that.

Since you are using "Thread.Sleep()", it suspends the main UI thread and you won't get the response until and unless 250msec passes out.

no..............i want the label to be updated exactly at that key pressing instant..........and print the count values at a speed little more than clock second..........

see the attachment.............

Please Check this:

now but the speed of the count is a little bit fast............wat should be done in order to reduce that speed..............

My guess is that you should use s++ or s-- within the timer code according to condition.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.