471,342 Members | 1,811 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,342 software developers and data experts.

Custom control clock.. refreshing troubles

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

}
}

Jun 27 '08 #1
3 1427

"Cecco" wrote:
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.

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

Jun 27 '08 #2
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
"Morten Wennevik [C# MVP]" <Mo************@hotmail.comha scritto nel
messaggio news:0E**********************************@microsof t.com...
>
"Cecco" wrote:
>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.

--
Happy Coding!
Morten Wennevik [C# MVP]
Jun 27 '08 #3
Alright,

I'll take a look at it tonight

--
Happy Coding!
Morten Wennevik [C# MVP]
"Cecco" wrote:
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
"Morten Wennevik [C# MVP]" <Mo************@hotmail.comha scritto nel
messaggio news:0E**********************************@microsof t.com...

"Cecco" wrote:
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.

--
Happy Coding!
Morten Wennevik [C# MVP]
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Do | last post: by
5 posts views Thread by Jensen Bredal | last post: by
reply views Thread by fwirtanen | last post: by
1 post views Thread by Mr Newbie | last post: by
6 posts views Thread by Scott Mueller | last post: by
8 posts views Thread by Arpan | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.