473,388 Members | 864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 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 1507

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Do | last post by:
Hi, I have a datagrid in a custom user control that must be refreshed after I click a button. My custom user control is named dtgDocuments. I can't find any kind of reload method for the...
5
by: Jensen Bredal | last post by:
Hello, I need to display self refreshing information on a web page written with asp.net. I would image that the info would be displayed either as part of a user control or a web control. How can...
0
by: fwirtanen | last post by:
I am building a custom composite control consisting of two drop downs, with parent/child dependancy. The child dropdownlist is updated through client callback when the parent index changes. ...
1
by: Mr Newbie | last post by:
Hi, Im doing something really stupid here, But I cant see the wood for the trees. This is some of the code for my custom composite control. It renders fine and the buttons do cause a Post to...
6
by: Scott Mueller | last post by:
I have a question about simple binding: (please forgive any syntax errors... I am at home, where I do not have Vb.Net installed, and I rely far too much on Vb's intellisense!) If I have two...
8
by: Arpan | last post by:
Consider the following code snippet (my main intention is to display the current time in a Label control as & when this ASPX page is accessed/refreshed): <script runat="server"> Class Clock...
1
by: PT | last post by:
Hi, I'm creating a library of basic constol that I often use, and am just getting to the whole custom process, I've started by creating something simple by inheriting from a textbox, I have two...
3
by: anacrisan | last post by:
I've created a custom calendar control and now I would like to add some AJAX behaviour to it. Basically I want to simulate the behaviour of a calendar in an Update Panel, meaning not refreshing the...
3
by: R.A.F. | last post by:
Hi, I have a custom control in which i have a property based on CollectionBase class. like the following one : //------- XGrid.cs file --------------// public ColumnsCollection Columns {
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.