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);
}
}
}