000
15.05.2010, 10:27 Uhr
Sebastian
|
Hallo,
ich habe folgenden Code aber irgendwie zeichnet er mir keine Uhr auf die Form. Das andere Problem das ich habe ist das bei der Funktion puplic uhr() ein Rückgabewert erwartet wird.
Code: |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;
namespace Uebung2Aufgabe1 { public partial class Form1 : Form { private Point center; private DateTime drawtime; private int lowest_size; public DateTime time = new DateTime(DateTime.Now.Ticks); private DateTime start = new DateTime(DateTime.Now.Ticks); public uhr() { if (this.Size.Width < this.Size.Height) lowest_size = this.Size.Width; else lowest_size = this.Size.Height; InitializeComponent(); center = new Point(this.Size.Width/2, this.Size.Height/2); }
//Kreis auf der Form positionieren Point getKreisPosition(int radius, int deg, Point p) { double x, y; x = Math.Sin((Math.PI / 180) * (deg)); y = Math.Sin((Math.PI / 180) * (deg - 90)); x *= radius; y *= radius; x += p.X; y += p.Y; return new Point((int)x, (int)y); } void uhrZeichnen(object sender, PaintEventArgs e) { Graphics g = e.Graphics; //Stundenzeiger int h = drawtime.Hour % 12; Point c = getCirclePosition(lowest_size/5-10,((h*60 + drawtime.Minute)/2),center); Pen pen = new Pen(Color.Red, 7); pen.EndCap = System.Drawing.Drawing2D.LineCap.Triangle; pen.StartCap = System.Drawing.Drawing2D.LineCap.Round; g.DrawLine(pen,center,c); //Minutenzeiger Point c = getCirclePosition(lowest_size/5,((drawtime.Minute*60 + drawtime.Second)/10),center); Pen pen = new Pen(Color.Blue, 5); pen.EndCap = System.Drawing.Drawing2D.LineCap.Triangle; pen.StartCap = System.Drawing.Drawing2D.LineCap.Round; g.DrawLine(pen, center, c); //Sekundenzeiger Point c = getCirclePosition(lowest_size / 4, ((drawtime.Second * 1000 + drawtime.Millisecond) / 166), center); Pen pen = new Pen(Color.Black, 3); pen.EndCap = System.Drawing.Drawing2D.LineCap.Triangle; pen.StartCap = System.Drawing.Drawing2D.LineCap.Round; g.DrawLine(pen, center, c); } void similar_clock_Resize(object sender, EventArgs e) { if (this.Size.Width < this.Size.Height) lowest_size = this.Size.Width; else lowest_size = this.Size.Height; this.center = new Point(this.Size.Width / 2, this.Size.Height / 2); this.Invalidate(true); } //Ticker intervall einstellen void TickerTick(object sender, EventArgs e) { drawtime = new DateTime((DateTime.Now.Ticks - start.Ticks) + time.Ticks); this.Invalidate(true); } public Form1() { InitializeComponent(); } } }
|
Ich denke das es nicht viel sein kann. Könnt ihr mir da weiterhelfen?
Danke. Gruß |