PC Review


Reply
Thread Tools Rate Thread

Custom control clock.. refreshing troubles

 
 
Cecco
Guest
Posts: n/a
 
      25th Jun 2008
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();
}





}
}

 
Reply With Quote
 
 
 
 
Morten Wennevik [C# MVP]
Guest
Posts: n/a
 
      25th Jun 2008

"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]

 
Reply With Quote
 
Cecco
Guest
Posts: n/a
 
      25th Jun 2008
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]" <(E-Mail Removed)> ha scritto nel
messaggio news:0E2298B4-AFFE-44C7-B31E-(E-Mail Removed)...
>
> "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]
>


 
Reply With Quote
 
Morten Wennevik [C# MVP]
Guest
Posts: n/a
 
      25th Jun 2008
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]" <(E-Mail Removed)> ha scritto nel
> messaggio news:0E2298B4-AFFE-44C7-B31E-(E-Mail Removed)...
> >
> > "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]
> >

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TIME (CLOCK) TROUBLES: Chuck--- Windows XP General 7 13th Nov 2006 09:46 AM
Troubles with associating a Toolbox Bitmap with a Custom Control.. lhummel@lhummel.com Microsoft Dot NET Framework Forms 1 7th Nov 2005 06:28 PM
Self refreshing user control/custom control. Jensen Bredal Microsoft ASP .NET 5 29th Dec 2004 12:10 PM
Refreshing a custom user control instance Do Microsoft ASP .NET 0 29th Oct 2003 05:33 AM
clock troubles Mike Windows XP Performance 1 14th Oct 2003 11:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:55 AM.