模拟时钟ana1 [英] analog clock ana1

查看:88
本文介绍了模拟时钟ana1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经开发过模拟时钟

这是代码

但这会带来问题


i used to develope an analog clock

here is the code

but it creates problems


using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

  
namespace ana1
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }
        public interface IClockModel
        {
            #region ClockDataEventArgs
            event EventHandler<ClockDataEventArgs> ClockChanging;
            event EventHandler<ClockDataEventArgs> ClockChanged;
            void SetClockInterval(TimeSpan timeSpan);
            IClockModel Start();
            IClockModel Continue();
            IClockModel Stop();
            ClockData ClockData { get; set; }
            bool IsRunning { get; }

        }

        private void DrawMarkers()
        {
            MarkerCanvas.Children.Clear();
            for (int i = 0; i < 60; ++i)
            {
                Rectangle markerRectangle = new Rectangle();
                if (i % 5 == 0)
                {
                    markerRectangle.Width = 3;
                    markerRectangle.Height = 8;
                    markerRectangle.Fill = new SolidColorBrush(Colors.White);
                    markerRectangle.RenderTransform = this.CreateTransformGroup(i * 6,
                        -(markerRectangle.Width / 2),
                        -(markerRectangle.Height * 2 + 4.5 - ClockFaceEllipse.StrokeThickness / 2 - this.clockHeight / 2));
                }
                else
                {
                    markerRectangle.Width = 1;
                    markerRectangle.Height = 4;
                    markerRectangle.Fill = new SolidColorBrush(Colors.White);
                    markerRectangle.RenderTransform = this.CreateTransformGroup(i * 6,
                        -(markerRectangle.Width / 2),
                        -(markerRectangle.Height * 2 + 12.75 - ClockFaceEllipse.StrokeThickness / 2 - this.clockHeight / 2));
                }
                MarkerCanvas.Children.Add(markerRectangle);
            }
        }
        private TransformGroup CreateTransformGroup(double angle, double firstTranslateXValue, double firstTranslateYValue)
        {
            TransformGroup transformGroup = new TransformGroup();
            TranslateTransform firstTranslate = new TranslateTransform();
            firstTranslate.X = firstTranslateXValue;
            firstTranslate.Y = firstTranslateYValue;
            transformGroup.Children.Add(firstTranslate);
            RotateTransform rotateTransform = new RotateTransform();
            rotateTransform.Angle = angle;
            transformGroup.Children.Add(rotateTransform);
            TranslateTransform secondTranslate = new TranslateTransform();
            secondTranslate.X = this.clockWidth / 2;
            secondTranslate.Y = this.clockHeight / 2;
            transformGroup.Children.Add(secondTranslate);
            return transformGroup;
        }
        private void DrawSecondsHand(ClockData clockData)
        {
            if (secondsHand != null && ClockHandsCanvas.Children.Contains(secondsHand)) ClockHandsCanvas.Children.Remove(secondsHand);
            secondsHand = this.CreateHand(this.secondsHandWidth, this.secondsHandHeight, new SolidColorBrush(Colors.Black), 0, 0, 0, null);
            secondsHand.RenderTransform = this.CreateTransformGroup(
            clockData.Seconds * 6, -this.secondsHandWidth / 2, -this.secondsHandHeight + 4.25);
            if (ClockHandsCanvas.Children.Contains(secondsHand) == false)
                ClockHandsCanvas.Children.Add(secondsHand);

        }

        public void Update(ClockData clockData)
        {
            this.DrawSecondsHand(clockData);
            this.DrawMinutesHand(clockData);
            this.DrawHoursHand(clockData);

        }
        public abstract class ClockBase : IClockModel
        {
            private ClockData clockData;
            protected bool isRunning;
            protected DispatcherTimer timer;
            public event EventHandler<ClockDataEventArgs> ClockChanging;
            public event EventHandler<ClockDataEventArgs> ClockChanged;
            public ClockBase()
            {
                clockData = new ClockData();
                timer = new DispatcherTimer();
                timer.Tick += new EventHandler(timer_Tick);
                this.SetClockInterval(new TimeSpan(0, 0, 0, 0, 1));
            }
            public virtual void SetClockInterval(TimeSpan timeSpan)
            {
                timer.Interval = timeSpan;
            }
            public ClockData ClockData
            {
                get
                {
                    return this.clockData;
                }
                set
                {
                    this.OnClockChangind(new ClockDataEventArgs(this.clockData));
                    this.clockData = value;
                    this.OnClockChanged(new ClockDataEventArgs(this.clockData));
                }
            }
            public bool IsRunning
            {
                get
                {
                    return this.isRunning;
                }
            }
            public abstract IClockModel Start();
            public abstract IClockModel Stop();
            public abstract IClockModel Continue();
            protected abstract void UpdateClockData(DateTime dateTime);
            protected virtual void OnClockChangind(ClockDataEventArgs e)
            {
                EventHandler<ClockDataEventArgs> temp = this.ClockChanging;
                if (temp != null)
                    temp(this, e);
            }
            protected virtual void OnClockChanged(ClockDataEventArgs e)
            {
                EventHandler<ClockDataEventArgs> temp = this.ClockChanged;
                if (temp != null)
                    temp(this, e);
            }
            private void timer_Tick(object sender, EventArgs e)
            {
                this.OnClockChangind(new ClockDataEventArgs(this.ClockData));
                this.UpdateClockData(DateTime.Now);
                this.OnClockChanged(new ClockDataEventArgs(this.ClockData));
            }
        }
        public class Clock : ClockBase
        {
            public static IClockModel Create()
            {
                return new Clock();
            }
            public override IClockModel Start()
            {
                if (IsRunning)
                    return this;
                timer.Start();
                isRunning = true;
                return this;
            }
            public override IClockModel Stop()
            {
                timer.Stop();
                isRunning = false;
                return this;
            }



            public override IClockModel Continue()
            {
                return this.Start();
            }



            protected override void UpdateClockData(DateTime dateTime)
            {
                this.ClockData.Update(dateTime);
            }

        }

        public class ClockPresenter
        {
            public Callback Response;
            public ClockPresenter(IClockView clockView, IClockModel clockModel)
            {
                this.ClockView = clockView;
                this.ClockModel = clockModel;
                this.ClockView.StartClock += new EventHandler(ClockView_StartClock);
                this.ClockView.StopClock += new EventHandler(ClockView_StopClock);
                this.ClockModel.ClockChanged += new EventHandler<ClockDataEventArgs>(ClockModel_ClockChanged);
            }
            public IClockView ClockView
            {
                get;
                set;
            }
            public IClockModel ClockModel
            {
                get;
                set;
            }



            private void ClockView_StopClock(object sender, EventArgs e)
            {
                this.ClockModel.Stop();
            }



            private void ClockView_StartClock(object sender, EventArgs e)
            {
                this.ClockModel.Start();
            }



            private void ClockModel_ClockChanged(object sender, ClockDataEventArgs e)
            {
                Callback temp = this.Response;
                if (temp != null)
                    temp(e.ClockData);
            }
        }

        //IClockModel clockModel = Clock.Create();

        //clockModel.ClockData = new ClockData().Update( DateTime.Now );



        //ClockPresenter presenter = new ClockPresenter( this.AnalogClockControl, clockModel );

        //presenter.Response += new Callback( this.AnalogClockControl.Update );



        //clockModel.Start();  }


    }



[snip]



[snip]

推荐答案

我不知所措.当您已经写完所有这些内容时,您问是否有一个时钟名称空间?现在,您发布代码并说它有问题",但不是问题,什么行有问题,如果有错误,或者您希望我们做什么?

你不想要帮助吗?

您已经发布了所有这些代码,但是您没有告诉我们该应用程序是WPF,或者当有人拒绝告诉我们它们是什么的时候,如果有人愚蠢到试图解决您的问题,就给我们XAML.
I''m at a loss. You asked if there was a clock namespace, when you''d already written all of this ? Now, you post the code and say it has ''problems'', but not what they are, what line has issues, if there''s an error, or what it is you want us to do ?

Do you not want help ?

You posted all this code, yet you didn''t tell us the app is WPF, or give us the XAML if someone was dumb enough to try to work out your problems when you refuse to tell us what they are ?


cshuhh写道:

但它会产生问题



您能在这里张贴问题(或您得到的错误,以便有人可以帮助您)吗?



Could you post the problems here (or the errors you get so that someone is able to help you)?


啊-解释了这个家伙是个白痴.他问了两次如何编写时钟的问题(他问是否有一个时钟命名空间....),然后发布了所有这些代码.

对于OP-不要那么傻.购买一本书并阅读它,您将无法期望下载随机代码并理解它,而无需了解您首先使用的语言.并且,将来可以正确标记您的问题.
Ah - that explains what an idiot this guy has been. He asked twice how to write a clock ( he asked if there''s a clock namespace.... ), then he posted all this code.

To the OP - don''t be so stupid. Buy a book and read it, you can''t expect to download random code and understand it without knowing about the languages you''re using first. And, tag your questions properly in future.


这篇关于模拟时钟ana1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆