Repintado Forms.

07/10/2003 - 21:04 por Jose Antonio | Informe spam
Alguna solución para el pintado correcto de los Forms en .Net?. Son
desastrosos en velicidad de pintado.

José Antonio
 

Leer las respuestas

#1 Mario Ruiz
08/10/2003 - 09:57 | Informe spam
Para evitar parpadeos en un control usamos lo siguiente. Los controles
heredan de este y sobreescribimos el método render, llamando al padre.


public class DobleBuffer : System.Windows.Forms.UserControl

{

private Bitmap Bmp;

private bool bmpReady=false;

public virtual void Render(Graphics g)

{

//Aqui dibujo lo que sea

}

public Bitmap GeneraBMP()

{

this.bmpReady=false;

this.Bmp=new Bitmap(this.Bounds.Width,this.Bounds.Height);

Graphics g=Graphics.FromImage(this.Bmp);

this.Render(g);


this.bmpReady=true;

return this.Bmp;

}

private void DobleBuffer_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)

{

//Verificamos que la imagen es válida

if (this.bmpReady==false)

this.GeneraBMP();

e.Graphics.DrawImage(this.Bmp,new Point(0,0));


}

protected void Refresca()

{

this.bmpReady=false;

this.Invalidate();

}

private void DobleBuffer_Resize(object sender, System.EventArgs e)

{

this.Refresca();

}

}

Preguntas similares