powered by simpleCommunicator - 2.0.60     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / Аналоговые часы
3 сообщений из 3, страница 1 из 1
Аналоговые часы
    #32661339
Фотография Easygoing
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Уважаемые господа, никто не знает, где стянуть компонент представляющий аналоговые часы?
...
Рейтинг: 0 / 0
Аналоговые часы
    #32661743
Фотография greenapple
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
 //------------------------------------------- 
 // ClockControl.cs © 2001 by Charles Petzold 
 //------------------------------------------- 
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace Petzold.ProgrammingWindowsWithCSharp
{
class ClockControl: UserControl
{
     DateTime dt;

     public ClockControl()
     {
          ResizeRedraw = true;
          Enabled = false;
     }
     public DateTime Time
     {
          get 
          { 
               return dt;  
          }
          set 
          { 
               Graphics grfx = CreateGraphics();
               InitializeCoordinates(grfx);

               Pen pen = new Pen(BackColor);

               if (dt.Hour != value.Hour)
               {
                    DrawHourHand(grfx, pen);
               }
               if (dt.Minute != value.Minute)
               {
                    DrawHourHand(grfx, pen);
                    DrawMinuteHand(grfx, pen);
               }
               if (dt.Second != value.Second)
               {
                    DrawMinuteHand(grfx, pen);
                    DrawSecondHand(grfx, pen);
               }
               if (dt.Millisecond != value.Millisecond)
               {
                    DrawSecondHand(grfx, pen);
               }          
               dt  = value;
               pen = new Pen(ForeColor);

               DrawHourHand(grfx, pen);
               DrawMinuteHand(grfx, pen);
               DrawSecondHand(grfx, pen);

               grfx.Dispose();
          }
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          Graphics grfx  = pea.Graphics;
          Pen      pen   = new Pen(ForeColor);
          Brush    brush = new SolidBrush(ForeColor);

          InitializeCoordinates(grfx);
          DrawDots(grfx, brush);
          DrawHourHand(grfx, pen);
          DrawMinuteHand(grfx, pen);
          DrawSecondHand(grfx, pen);
     }
     void InitializeCoordinates(Graphics grfx)
     {
          if (Width == 0 || Height == 0)
               return;

          grfx.TranslateTransform(Width / 2, Height / 2);

          float fInches = Math.Min(Width / grfx.DpiX, Height / grfx.DpiY);

          grfx.ScaleTransform(fInches * grfx.DpiX / 2000,
                              fInches * grfx.DpiY / 2000);
     }
     void DrawDots(Graphics grfx, Brush brush)
     {
          for (int i = 0; i < 60; i++)
          {
               int iSize = i % 5 == 0 ? 100 : 30;

               grfx.FillEllipse(brush, 0 - iSize / 2, -900 - iSize / 2, 
                                       iSize, iSize);
               grfx.RotateTransform(6);
          }          
     }
     protected virtual void DrawHourHand(Graphics grfx, Pen pen)
     {
          GraphicsState gs = grfx.Save();
          grfx.RotateTransform(360f * Time.Hour / 12 +
                                30f * Time.Minute / 60);

          grfx.DrawPolygon(pen, new Point[]
                              {
                                   new Point(0,  150), new Point( 100, 0),
                                   new Point(0, -600), new Point(-100, 0)
                              });
          grfx.Restore(gs);
     }
     protected virtual void DrawMinuteHand(Graphics grfx, Pen pen)
     {
          GraphicsState gs = grfx.Save();
          grfx.RotateTransform(360f * Time.Minute / 60 +
                                 6f * Time.Second / 60);

          grfx.DrawPolygon(pen, new Point[]
                              {
                                   new Point(0,  200), new Point( 50, 0),
                                   new Point(0, -800), new Point(-50, 0)
                              });
          grfx.Restore(gs);
     }
     protected virtual void DrawSecondHand(Graphics grfx, Pen pen)
     {
          GraphicsState gs = grfx.Save();
          grfx.RotateTransform(360f * Time.Second / 60 +
                                 6f * Time.Millisecond / 1000);

          grfx.DrawLine(pen, 0, 0, 0, -800);
          grfx.Restore(gs);          
     }
}
}
...
Рейтинг: 0 / 0
Аналоговые часы
    #32663440
Фотография Easygoing
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Спасибо!
...
Рейтинг: 0 / 0
3 сообщений из 3, страница 1 из 1
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / Аналоговые часы
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]