I have an application in which I need to move my drawing continuosly when the user moves the mouse. The problem is that I am getting a flickering when Invalidate function is called after mouse move. Any solution? Following demostrates the sample:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
namespace DrawPad
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
private int currentPointX=0, currentPointY=0;
private Rectangle prevRectangle = new Rectangle(0,0,120,30);
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.SystemColors.ControlText;
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
protected override void OnPaint(PaintEventArgs e)
{
SolidBrush mainBrush = new SolidBrush(Color.Red);
e.Graphics.FillRectangle(mainBrush, currentPointX, currentPointY, 120, 30);
mainBrush.Dispose();
}
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.Invalidate(prevRectangle);
currentPointX = e.X;
currentPointY = e.Y;
prevRectangle.X = currentPointX;
prevRectangle.Y = currentPointY;
}
private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
{
return;
}
currentPointX = e.X;
currentPointY = e.Y;
}
}
}

jugendra singh2 reputationPosted Feb 24, 2006, 3:52 AM EST
Jugendra,
Hello friend i think you are using window's listBox. You are using Images and text in listBox. When u scroll mouse over it then your problem occurs. Please use colorListBox it can solve your problem.Search it on net using 'ColorListBox' sure it will solve urs problem.
Thank.
saumitra tamrakar5 reputationPosted Jul 23, 2006, 11:55 PM EDT
thanks
saumitra tamrakar5 reputationPosted Jul 24, 2006, 12:01 AM EDT
please tell me in detail abt listbox n colorlistbox as i m facing same problem like above question but i have not use both listbox or colorlistbox , simple i m calling image and call invalidate
function but when we load/refresh form it took too much time and load in sections like each image
please tell me the solution for it
thanks