반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Kotlin
- gas
- 파이썬
- c#
- array
- Mac
- django
- Github
- PANDAS
- math
- hive
- Google Excel
- Excel
- Java
- matplotlib
- Python
- PySpark
- numpy
- Google Spreadsheet
- dataframe
- google apps script
- Tkinter
- SQL
- Apache
- PostgreSQL
- GIT
- Redshift
- list
- string
Archives
- Today
- Total
달나라 노트
C# Samples : Graphic Timer 3개 본문
728x90
반응형
using System;
using System.Windows.Forms;
using System.Drawing;
using WMPLib;
class CardCatch
{
public static void Main()
{
// Constatns //
Constants cts = new Constants();
Form fm = new Form();
PictureBox pb_30 = new PictureBox();
PictureBox pb_20 = new PictureBox();
PictureBox pb_15 = new PictureBox();
Timer tm_30 = new Timer();
Timer tm_20 = new Timer();
Timer tm_15 = new Timer();
int min_30 = cts.min_30;
int sec_30 = min_30 * 60;
int min_20 = cts.min_20;
int sec_20 = min_20 * 60;
int min_15 = cts.min_15;
int sec_15 = min_15 * 60;
WindowsMediaPlayer wmp_30 = new WindowsMediaPlayer();
WindowsMediaPlayer wmp_20 = new WindowsMediaPlayer();
WindowsMediaPlayer wmp_15 = new WindowsMediaPlayer();
Console.WriteLine(cts.dir_current);
// Settings //
fm.ClientSize = new Size(cts.form_client_size_width, cts.form_client_size_height);
fm.Text = "타이머";
pb_30.Parent = fm;
pb_30.Width = cts.pb_width;
pb_30.Height = cts.pb_height;
pb_30.Location = new Point(cts.pb_width * 0, 0);
pb_20.Parent = fm;
pb_20.Width = cts.pb_width;
pb_20.Height = cts.pb_height;
pb_20.Location = new Point(cts.pb_width * 1, 0);
pb_15.Parent = fm;
pb_15.Width = cts.pb_width;
pb_15.Height = cts.pb_height;
pb_15.Location = new Point(cts.pb_width * 2, 0);
tm_30.Interval = cts.timer_interval;
tm_20.Interval = cts.timer_interval;
tm_15.Interval = cts.timer_interval;
wmp_30.URL = cts.dir_mp3;
wmp_30.controls.stop();
wmp_20.URL = cts.dir_mp3;
wmp_20.controls.stop();
wmp_15.URL = cts.dir_mp3;
wmp_15.controls.stop();
// Event //
void pb_inner_ellipse_30(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
float end_angle = (float)360 / (cts.min_30 * 60) * (cts.min_30 * 60 - sec_30);
g.FillPie(cts.brush_outer_pie, cts.outer_pie_x, cts.outer_pie_y, cts.outer_pie_width, cts.outer_pie_height, -90, end_angle);
g.FillEllipse(cts.brush_inner_ellipse, cts.inner_ellipse_x, cts.inner_ellipse_y, cts.inner_ellipse_width, cts.inner_ellipse_height);
int min_part = (int)Math.Floor((double)sec_30 / 60);
int sec_part = sec_30 - min_part * 60;
string time_string = min_part.ToString().PadLeft(2, '0') + ":" + sec_part.ToString().PadLeft(2, '0');
SizeF time_string_size = g.MeasureString(time_string, cts.font);
float time_string_x = cts.pb_width / 2 - time_string_size.Width / 2;
float time_string_y = cts.pb_height / 2 - time_string_size.Height / 2;
g.DrawString(time_string, cts.font, cts.brush_string, time_string_x, time_string_y);
}
pb_30.Paint += new PaintEventHandler(pb_inner_ellipse_30);
void pb_inner_ellipse_20(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
float end_angle = (float)360 / (cts.min_20 * 60) * (cts.min_20 * 60 - sec_20);
g.FillPie(cts.brush_outer_pie, cts.outer_pie_x, cts.outer_pie_y, cts.outer_pie_width, cts.outer_pie_height, -90, end_angle);
g.FillEllipse(cts.brush_inner_ellipse, cts.inner_ellipse_x, cts.inner_ellipse_y, cts.inner_ellipse_width, cts.inner_ellipse_height);
int min_part = (int)Math.Floor((double)sec_20 / 60);
int sec_part = sec_20 - min_part * 60;
string time_string = min_part.ToString().PadLeft(2, '0') + ":" + sec_part.ToString().PadLeft(2, '0');
SizeF time_string_size = g.MeasureString(time_string, cts.font);
float time_string_x = cts.pb_width / 2 - time_string_size.Width / 2;
float time_string_y = cts.pb_height / 2 - time_string_size.Height / 2;
g.DrawString(time_string, cts.font, cts.brush_string, time_string_x, time_string_y);
}
pb_20.Paint += new PaintEventHandler(pb_inner_ellipse_20);
void pb_inner_ellipse_15(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
float end_angle = (float)360 / (cts.min_15 * 60) * (cts.min_15 * 60 - sec_15);
g.FillPie(cts.brush_outer_pie, cts.outer_pie_x, cts.outer_pie_y, cts.outer_pie_width, cts.outer_pie_height, -90, end_angle);
g.FillEllipse(cts.brush_inner_ellipse, cts.inner_ellipse_x, cts.inner_ellipse_y, cts.inner_ellipse_width, cts.inner_ellipse_height);
int min_part = (int)Math.Floor((double)sec_15 / 60);
int sec_part = sec_15 - min_part * 60;
string time_string = min_part.ToString().PadLeft(2, '0') + ":" + sec_part.ToString().PadLeft(2, '0');
SizeF time_string_size = g.MeasureString(time_string, cts.font);
float time_string_x = cts.pb_width / 2 - time_string_size.Width / 2;
float time_string_y = cts.pb_height / 2 - time_string_size.Height / 2;
g.DrawString(time_string, cts.font, cts.brush_string, time_string_x, time_string_y);
}
pb_15.Paint += new PaintEventHandler(pb_inner_ellipse_15);
void tm_tick_30(object sender, EventArgs e)
{
sec_30 = sec_30 - 1;
if (sec_30 <= 10)
{
if (sec_30 <= 0)
{
sec_30 = 0;
}
else
{
wmp_30.controls.play();
}
}
pb_30.Invalidate();
}
tm_30.Tick += new EventHandler(tm_tick_30);
void pb_click_30(object sender, EventArgs e)
{
if (tm_30.Enabled)
{
sec_30 = cts.min_30 * 60;
tm_30.Stop();
wmp_30.controls.stop();
pb_30.Invalidate();
}
else
{
tm_30.Start();
}
}
pb_30.Click += new EventHandler(pb_click_30);
void tm_tick_20(object sender, EventArgs e)
{
sec_20 = sec_20 - 1;
if (sec_20 <= 10)
{
if (sec_20 <= 0)
{
sec_20 = 0;
}
else
{
wmp_20.controls.play();
}
}
pb_20.Invalidate();
}
tm_20.Tick += new EventHandler(tm_tick_20);
void pb_click_20(object sender, EventArgs e)
{
if (tm_20.Enabled)
{
sec_20 = cts.min_20 * 60;
tm_20.Stop();
wmp_20.controls.stop();
pb_20.Invalidate();
}
else
{
tm_20.Start();
}
}
pb_20.Click += new EventHandler(pb_click_20);
void tm_tick_15(object sender, EventArgs e)
{
sec_15 = sec_15 - 1;
if (sec_15 <= 10)
{
if (sec_15 <= 0)
{
sec_15 = 0;
}
else
{
wmp_15.controls.play();
}
}
pb_15.Invalidate();
}
tm_15.Tick += new EventHandler(tm_tick_15);
void pb_click_15(object sender, EventArgs e)
{
if (tm_15.Enabled)
{
sec_15 = cts.min_15 * 60;
tm_15.Stop();
wmp_15.controls.stop();
pb_15.Invalidate();
}
else
{
tm_15.Start();
}
}
pb_15.Click += new EventHandler(pb_click_15);
// Main //
Application.Run(fm);
}
}
class Constants
{
public int form_client_size_width;
public int form_client_size_height = 170;
public int pb_width;
public int pb_height;
public int inner_ellipse_width;
public int inner_ellipse_height;
public int inner_ellipse_x;
public int inner_ellipse_y;
public int outer_pie_width;
public int outer_pie_height;
public int outer_pie_x = 0;
public int outer_pie_y = 0;
public int min_30 = 30;
public int min_20 = 20;
public int min_15 = 15;
public int timer_interval = 1000;
public Font font = new Font("Arial", 20);
public SolidBrush brush_inner_ellipse = new SolidBrush(Color.Gray);
public SolidBrush brush_outer_pie = new SolidBrush(Color.SkyBlue);
public SolidBrush brush_string = new SolidBrush(Color.White);
public string dir_current = System.Environment.CurrentDirectory.ToString();
public string dir_mp3 = "\\mp3\\sample.mp3";
public Constants()
{
this.form_client_size_width = this.form_client_size_height * 3;
this.pb_width = this.form_client_size_height;
this.pb_height = this.form_client_size_height;
this.outer_pie_width = this.pb_width;
this.outer_pie_height = this.pb_height;
this.inner_ellipse_width = (int)Math.Round((double)this.form_client_size_height / 1.5, 0);
this.inner_ellipse_height = (int)Math.Round((double)this.form_client_size_height / 1.5, 0);
this.inner_ellipse_y = (int)Math.Round((double)this.form_client_size_height / 2, 0) - (int)Math.Round((double)this.inner_ellipse_height / 2, 0);
this.inner_ellipse_x = (int)Math.Round((double)this.form_client_size_width / 3 / 2, 0) - (int)Math.Round((double)this.inner_ellipse_width / 2, 0);
this.dir_mp3 = this.dir_current + this.dir_mp3;
this.dir_mp3 = this.dir_mp3.Replace("\\", "\\\\");
}
}
728x90
반응형
'C# > C# Samples' 카테고리의 다른 글
C# Samples : 포물선 운동 (Parabolic Motion) (0) | 2022.05.28 |
---|---|
C# Sample : 주사위 번호 맞추기 (0) | 2022.05.15 |
C# Sample : 타이머 30분, 20분, 15분 (0) | 2022.04.21 |
Comments