I have a PictureBox image in a form which is moving with the mouse movement on the panel.
It's moving as I want it, however it's flickering all the time (like refreshes) and I learnt that it's a problem with forms.
I tried the following lines of code in the constructor of my form but no success:
SetStyle( ControlStyles.ResizeRedraw, true );
SetStyle( ControlStyles.UserPaint, true );
SetStyle( ControlStyles.AllPaintingInWmPaint, true );
SetStyle( ControlStyles.OptimizedDoubleBuffer, true );
This is the event handler for the mouse move if it helps to see all the picture. chipHolder is a panel and image is the image imported from file respectively.
private void grid_MouseMove(object sender, MouseEventArgs e)
{
columnPosition = e.X;
if (columnPosition != -1)
{
if (!(columnPosition < 35 || columnPosition > 610))
{
chipHolder.Controls.Clear();
PictureBox picBox = new PictureBox();
chipHolder.Controls.Add(picBox);
picBox.Image = image;
picBox.Width = image.Width;
picBox.Height = image.Height;
picBox.Location = new Point(columnPosition - 33, 0);
picBox.Show();
}
}
chipHolder.Update();
}
Any ideas?