Custom control clock.. refreshing troubles

C

Cecco

Hi everybody,

I just made a simple control called clock for including a "windows sidebar
modern clock" in my applications.
It works fine but there some "flashing effect" when the control refresh.
For further information i posted my code.

Do you think it's possible to change some params to resolve the problem??

Tahnks in advance

Cecco

Note:
The control has 1 picture box in the background with clock
In the foreground there's a Panel with background set to trasparent

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace OAGControlLibrary
{
public partial class Clock : UserControl
{
private float oraAngle;
private float minAngle;
private float secAngle;

public Clock()
{
InitializeComponent();
}

private void panel1_Paint(object sender, PaintEventArgs e)
{

Graphics g = this.panel1.CreateGraphics();

g.Transform = Rotate(minAngle);
g.DrawImage(new Bitmap(Properties.Resources.modern_m), new
Point((panel1.Width / 2) - 6, 4));

g.Transform = Rotate(oraAngle);
g.DrawImage(new Bitmap(Properties.Resources.modern_h), new
Point((panel1.Width / 2) - 6, 4));

g.Transform = Rotate(secAngle);
g.DrawImage(new Bitmap(Properties.Resources.modern_s), new
Point((panel1.Width / 2) - 6, 4));



}



private float TransformMin()
{
DateTime d = new DateTime();
d = DateTime.Now;
float Time = (float)d.Minute + ((float)d.Second / 60);
float angle = Time / 60 * 360;
return angle;

}
private float TransformOra()
{
DateTime d = new DateTime();
d = DateTime.Now;
float Time;
if (d.Hour >= 12)
{
Time = ((float)d.Hour - 12) + ((float)d.Minute/60);
}
else
{
Time = (float)d.Hour + ((float)d.Minute /60);
}
float angle = Time / 12 * 360;
return angle;

}

private float TransformSec()
{
DateTime d = new DateTime();
d = DateTime.Now;
float Time = (float)d.Second;
float angle = Time / 60 * 360;
return angle;

}

private Matrix Rotate(float angle)
{
Matrix m = new Matrix();
m.RotateAt(angle, new PointF(panel1.Width/2,panel1.Height/2));
return m;

}

private void timer1_Tick(object sender, EventArgs e)
{
oraAngle = TransformOra();
minAngle = TransformMin();
secAngle = TransformSec();
this.panel1.Refresh();
}





}
}
 
M

Morten Wennevik [C# MVP]

Cecco said:
Hi everybody,

I just made a simple control called clock for including a "windows sidebar
modern clock" in my applications.
It works fine but there some "flashing effect" when the control refresh.
For further information i posted my code.

Do you think it's possible to change some params to resolve the problem??

Tahnks in advance

Cecco

Hi Cecco,

Try adding DoubleBuffered = true in your Clock constructor.
 
C

Cecco

Thanks for your answer, but the property doublebuffered was already set to
true.

If you want I can send you my control project.. I you don't mind!

Thanks a lot

Cecco
 
M

Morten Wennevik [C# MVP]

Alright,

I'll take a look at it tonight

--
Happy Coding!
Morten Wennevik [C# MVP]


Cecco said:
Thanks for your answer, but the property doublebuffered was already set to
true.

If you want I can send you my control project.. I you don't mind!

Thanks a lot

Cecco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top