By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,671 Members | 1,387 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,671 IT Pros & Developers. It's quick & easy.

Custom control clock.. refreshing troubles

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a

"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

P: n/a
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

P: n/a
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.