hi everyone,
this is my first post here.
i need a help please...
(i'm a beginner in c#)
i have to make two analog clocks with visual studio in c#,wich they must be in a different time zone beside each other,one with our time and the second could be any place in the world.
i made the first analog clock and than i copied it and i made a new class for it,but when i start debugging the second clock comes under the first one and attached to it,how can i move the second clock parallel to the right side of the first clock??
this is the main code wich contain the ode of the first clock:
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Drawing.Drawing2D;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace analoge_uhr<br />
{<br />
public partial class Form1 : Form<br />
{<br />
private Clock uhr1;<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
<br />
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);<br />
this.SetStyle(ControlStyles.UserPaint, true);<br />
this.SetStyle(ControlStyles.DoubleBuffer, true);<br />
uhr1 = new Clock();<br />
}<br />
protected override void OnPaint(PaintEventArgs e)<br />
{<br />
base.OnPaint(e);<br />
System.Drawing.Graphics gr = e.Graphics;<br />
<br />
Rectangle rec = new Rectangle(20, 20, 250, 250);<br />
LinearGradientBrush linearbrush = new LinearGradientBrush(rec, Color.Yellow, Color.Green, 225);<br />
gr.FillEllipse(linearbrush, 20, 20, 200, 200);<br />
linearbrush.LinearColors = new Color[] { Color.Silver, Color.Silver, };<br />
gr.FillEllipse(linearbrush, 30, 30, 180, 180);<br />
linearbrush.LinearColors = new Color[] { Color.Black, Color.Black };<br />
gr.FillEllipse(linearbrush, 33, 33, 174, 174);<br />
SolidBrush solidbrush = new SolidBrush(Color.White);<br />
Font textFont = new Font("Arial Bold", 12F);<br />
gr.DrawString("12", textFont, solidbrush, 109, 40);<br />
gr.DrawString("11", textFont, solidbrush, 75, 50);<br />
gr.DrawString("10", textFont, solidbrush, 47, 75);<br />
gr.DrawString("9", textFont, solidbrush, 43, 110);<br />
gr.DrawString("8", textFont, solidbrush, 52, 145);<br />
gr.DrawString("7", textFont, solidbrush, 75, 170);<br />
gr.DrawString("6", textFont, solidbrush, 113, 180);<br />
gr.DrawString("5", textFont, solidbrush, 150, 170);<br />
gr.DrawString("4", textFont, solidbrush, 173, 145);<br />
gr.DrawString("3", textFont, solidbrush, 182, 110);<br />
gr.DrawString("2", textFont, solidbrush, 173, 75);<br />
gr.DrawString("1", textFont, solidbrush, 150, 50);<br />
gr.TranslateTransform(120, 120, MatrixOrder.Append);<br />
int hour = DateTime.Now.Hour;<br />
int min = DateTime.Now.Minute;<br />
int sec = DateTime.Now.Second;<br />
Pen hourPen = new Pen(Color.White, 2);<br />
Pen minutePen = new Pen(Color.LightGray, 2);<br />
Pen secondPen = new Pen(Color.Red, 1);<br />
double secondAngle = 2.0 * Math.PI * sec / 60.0;<br />
double minuteAngle = 2.0 * Math.PI * (min + sec / 60.0) / 60.0;<br />
double hourAngle = 2.0 * Math.PI * (hour + min / 60.0) / 12.0;<br />
Point centre = new Point(0, 0);<br />
Point hourHand = new Point((int)(40 * Math.Sin(hourAngle)),<br />
(int)(-40 * Math.Cos(hourAngle)));<br />
gr.DrawLine(hourPen, centre, hourHand);<br />
Point minHand = new Point((int)(70 * Math.Sin(minuteAngle)),<br />
(int)(-70 * Math.Cos(minuteAngle)));<br />
gr.DrawLine(minutePen, centre, minHand);<br />
Point secHand = new Point((int)(70 * Math.Sin(secondAngle)),<br />
(int)(-70 * Math.Cos(secondAngle)));<br />
gr.DrawLine(secondPen, centre, secHand);<br />
<br />
uhr1.daw(e.Graphics);<br />
<br />
Invalidate();<br />
}<br />
<br />
} <br />
}<br />
and here is the code for the second clock,wich i opened for it a new class:
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Drawing;<br />
using System.Drawing.Drawing2D;<br />
<br />
namespace analoge_uhr<br />
{<br />
class Clock<br />
{<br />
<br />
public void daw(System.Drawing.Graphics g){<br />
<br />
Rectangle rec = new Rectangle(20, 20, 250, 250);<br />
LinearGradientBrush linearbrush = new LinearGradientBrush(rec, Color.Blue, Color.BlueViolet, 225);<br />
g.FillEllipse(linearbrush, 20, 20, 200, 200);<br />
linearbrush.LinearColors = new Color[] { Color.Silver, Color.Silver, };<br />
g.FillEllipse(linearbrush, 30, 30, 180, 180);<br />
linearbrush.LinearColors = new Color[] { Color.Black, Color.Black };<br />
g.FillEllipse(linearbrush, 33, 33, 174, 174);<br />
SolidBrush solidbrush = new SolidBrush(Color.White);<br />
Font textFont = new Font("Arial Bold", 12F);<br />
g.DrawString("12", textFont, solidbrush, 109, 40);<br />
g.DrawString("11", textFont, solidbrush, 75, 50);<br />
g.DrawString("10", textFont, solidbrush, 47, 75);<br />
g.DrawString("9", textFont, solidbrush, 43, 110);<br />
g.DrawString("8", textFont, solidbrush, 52, 145);<br />
g.DrawString("7", textFont, solidbrush, 75, 170);<br />
g.DrawString("6", textFont, solidbrush, 113, 180);<br />
g.DrawString("5", textFont, solidbrush, 150, 170);<br />
g.DrawString("4", textFont, solidbrush, 173, 145);<br />
g.DrawString("3", textFont, solidbrush, 182, 110);<br />
g.DrawString("2", textFont, solidbrush, 173, 75);<br />
g.DrawString("1", textFont, solidbrush, 150, 50);<br />
g.TranslateTransform(120, 120, MatrixOrder.Append);<br />
int hour = DateTime.Now.Hour;<br />
int min = DateTime.Now.Minute;<br />
int sec = DateTime.Now.Second;<br />
Pen hourPen = new Pen(Color.White, 2);<br />
Pen minutePen = new Pen(Color.LightGray, 2);<br />
Pen secondPen = new Pen(Color.Red, 1);<br />
double secondAngle = 2.0 * Math.PI * sec / 60.0;<br />
double minuteAngle = 2.0 * Math.PI * (min + sec / 60.0) / 60.0;<br />
double hourAngle = 2.0 * Math.PI * (hour + min / 60.0) / 12.0;<br />
Point centre = new Point(0, 0);<br />
Point hourHand = new Point((int)(40 * Math.Sin(hourAngle)),<br />
(int)(-40 * Math.Cos(hourAngle)));<br />
g.DrawLine(hourPen, centre, hourHand);<br />
Point minHand = new Point((int)(70 * Math.Sin(minuteAngle)),<br />
(int)(-70 * Math.Cos(minuteAngle)));<br />
g.DrawLine(minutePen, centre, minHand);<br />
Point secHand = new Point((int)(70 * Math.Sin(secondAngle)),<br />
(int)(-70 * Math.Cos(secondAngle)));<br />
g.DrawLine(secondPen, centre, secHand);<br />
<br />
}<br />
}<br />
<br />
}<br />
<br />
and thanky you...
modified on Saturday, April 30, 2011 4:31 PM
|