báo cáo csahp đề tài tạo đồng hồ

22 192 0
báo cáo csahp đề tài tạo đồng hồ

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Giảng Viên: Đặng Kiên Cường Thành Viên Nhóm 5: Nguyễn Văn Anh Phan Trung Dũng Phan Tú Nguyễn Hữu Thi Đề Tài Tạo Đồng hồ TỔNG QUAN BÀI BÁO CÁO PHẦN I: GIỚI THIỆU TỔNG QUÁT VỀ ĐỒNG HỒ PHẦN II: XÂY DƯNG CHƯƠNG TRÌNH PHẦN III: KẾT LUẬN PHẦN I: GIỚI THIỆU TỔNG QUÁT VỀ ĐỒNG HỒ • Mục đích thể hiện chương trình: • Được dùng để xem thời gian ngày • Bên cạnh biết thứ, ngày, tháng, năm mà muốn biết PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH • • • • • Chúng ta cần giao diện Form và: Một Menustrip Một Lable Một MonthCalendar Một Timer PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Chúng ta cần có hàm thư viện sau: using System; using System.Drawing; using System.Windows.Forms; using System.Drawing.Drawing2D; PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Tạo góc alpha cho kim double alphaS = 90 - DateTime.Now.Second * 6; double alphaM = 90 - DateTime.Now.Minute * DateTime.Now.Second * 0.1; double alphaH = 90 - DateTime.Now.Hour * 30 -DateTime.Now.Minute * 0.5 - DateTime.Now.Second * 0.5 / 60; PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Gán đối tượng vẽ Image bt = new Bitmap(Width, Height); Graphics grfx = Graphics.FromImage(bt); PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Code vẽ vòng tròn Color cl = Color.FromArgb(198, 198, 198); Color cl1 = Color.FromArgb(224, 224, 224); Color cl2 = Color.FromArgb(125, 125, 125); grfx.FillEllipse(new SolidBrush(cl2), new Rectangle(new Point(42, 42), new Size(315, 315))); grfx.FillEllipse(new SolidBrush(cl), new Rectangle(new Point(50, 50), new Size(300, 300))); grfx.FillEllipse(new SolidBrush(cl1), new Rectangle(new Point(70, 70), new Size(260, 260))); PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Vẽ số đồng hồ grfx.DrawString("9", new Font("Alcohol Licks", 16.0f), Brushes.Black, 48, 193); grfx.DrawString("12", new Font("Alcohol Licks", 16.0f), Brushes.Black, 188, 50); grfx.DrawString("3", new Font("Alcohol Licks", 16.0f), Brushes.Black, 330, 193); grfx.DrawString("6", new Font("Alcohol Licks", 16.0f), Brushes.Black, 187, 333); grfx.DrawString("1", new Font("Licenz Plate", 18.0f), Brushes.Black, 267, 70); grfx.DrawString("2", new Font("Licenz Plate", 18.0f), Brushes.Black, 320, 120); PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Vẽ số đồng hồ grfx.DrawString("4", new Font("Licenz Plate", 18.0f), Brushes.Black, 318, 267); grfx.DrawString("5", new Font("Licenz Plate", 18.0f), Brushes.Black, 263, 317); grfx.DrawString("7", new Font("Licenz Plate", 18.0f), Brushes.Black, 120, 318); grfx.DrawString("8", new Font("Licenz Plate", 18.0f), Brushes.Black, 65, 268); grfx.DrawString("10", new Font("Licenz Plate", 18.0f), Brushes.Black, 68, 119); grfx.DrawString("11", new Font("Licenz Plate", 18.0f), Brushes.Black, 120, 68); PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Vẽ dấu chấm đồng hồ for (int i = 0; i < 360; i++) { int x = x0 + (int)Math.Round(150 * Math.Cos(i * Math.PI / 180)); int y = y0 - (int)Math.Round(150 * Math.Sin(i * Math.PI / 180)); if (i % == && i != && i != 30 && i != 60 && i != 120 && i != 150 && i != 210 && i != 240 && i != 300 && i != 330 && i != 90 && i != 180 && i != 270) grfx.FillEllipse(Brushes.Black , x - 2, y - 2, 6, 6); } PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Viết chữ lên đồng hồ grfx.DrawString("ĐH Lạc Hồng", new Font("Verdana", 17.0f), Brushes.Red, x0 - 80, y0 + 20); grfx.DrawString("Clock", new Font("Tahoma", 12.0f), Brushes.Red, x0 - 18, y0 - 30); grfx.DrawString("Design By Group 5", new Font("Times New Roman", 15.0f, FontStyle.Italic), Brushes.Red, x0 - 80, y0 + 50); PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Tạo ngày tháng năm đồng hồ int d = DateTime.Now.Day; int m = DateTime.Now.Month; int year = DateTime.Now.Year; grfx.DrawString(string.Format("{0} - {1} - {2}", d, m, year), new Font("Tahoma", 14.0f), Brushes.Red, 140, 130); PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Vẽ kim giây double radAlphaS = alphaS * Math.PI / 180; int xs = x0 + (int)Math.Round(R1 * Math.Cos(radAlphaS)); int ys = y0 - (int)Math.Round(R1 * Math.Sin(radAlphaS)); Pen customPen1 = new Pen(Color.Red , 2); GraphicsPath customEndPath1 = new GraphicsPath(); customEndPath1.AddLine(0, 1, -2, -2); customEndPath1.AddLine(0, 1, 2, -2); customPen1.CustomEndCap = new CustomLineCap(null, customEndPath1); grfx.DrawLine(customPen1, 200, 200, xs, ys); PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Vẽ kim phút double radAlphaM = alphaM * Math.PI / 180; float xm = (float)(x0 + R2 * Math.Cos(radAlphaM)); float ym = (float)(y0 - R2 * Math.Sin(radAlphaM)); Pen customPen = new Pen(Color.Black , 4); GraphicsPath customEndPath = new GraphicsPath(); customEndPath.AddLine(0, 1, -1, -1); customEndPath.AddLine(0, 1, 1, -1); customPen.CustomEndCap = new CustomLineCap(null, customEndPath); grfx.DrawLine(customPen, 200, 200, xm, ym); PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Vẽ kim double radAlphaH = alphaH * Math.PI / 180; int xh = x0 + (int)Math.Round(R3 * Math.Cos(radAlphaH)); int yh = y0 - (int)Math.Round(R3 * Math.Sin(radAlphaH)); Pen customPen2 = new Pen(Color.Black , 5); GraphicsPath customEndPath2 = new GraphicsPath(); customEndPath2.AddLine(0, 1, -1, -1); customEndPath2.AddLine(0, 1, 1, -1); customPen2.CustomEndCap=newCustomLineCap(null,customEndPath2); grfx.DrawLine(customPen2, 200, 200, xh, yh); PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH • Thực vẽ hiển thị lên Form private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = CreateGraphics(); PaintClock(g); pea = e; } static PaintEventArgs pea; private void DongHo_Tick_1(object sender, EventArgs e) { Form1_Paint(sender, pea); } PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Tạo đồng hồ điện tử public string GetTime() { string TimeInString = ""; int hour = DateTime.Now.Hour; int = DateTime.Now.Minute; int sec = DateTime.Now.Second; if (hour < 10) { TimeInString = "0" + hour.ToString(); else { TimeInString = hour.ToString(); } } PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH if (min < 10) { TimeInString += ":" + "0" + min.ToString(); else { TimeInString += ":" + min.ToString(); } if (sec < 10) { TimeInString += ":" + "0" + sec.ToString(); else { TimeInString += ":" + sec.ToString(); } return TimeInString; } } PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Tạo Lịch Cập nhật thời gian cho MonthCalendar private void Form1_Load(object sender, EventArgs e) { monthCalendar1.TodayDate = DateTime.Now.Date; } PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Tạo âm ticktac âm đóng form System.Media.SoundPlayer play = new System.Media.SoundPlayer(); play.SoundLocation = "dong cua.wav"; play.Play(); DialogResult result = MessageBox.Show("BẠN MUỐN THOÁT CHƯƠNG TRÌNH ?", "THÔNG BÁO ", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (Convert.ToString(result) == "Yes") { Application.Exit(); } else { System.Media.SoundPlayer play1 = new System.Media.SoundPlayer(); play1.SoundLocation = "tichtac32.wav"; play1.PlayLooping(); } [...]... TRÌNH Viết chữ lên đồng hồ grfx.DrawString("ĐH Lạc Hồng", new Font("Verdana", 17.0f), Brushes.Red, x0 - 80, y0 + 20); grfx.DrawString("Clock", new Font("Tahoma", 12.0f), Brushes.Red, x0 - 18, y0 - 30); grfx.DrawString("Design By Group 5", new Font("Times New Roman", 15.0f, FontStyle.Italic), Brushes.Red, x0 - 80, y0 + 50); PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Tạo ngày tháng năm trên đồng hồ int d = DateTime.Now.Day;... Graphics g = CreateGraphics(); PaintClock(g); pea = e; } static PaintEventArgs pea; private void DongHo_Tick_1(object sender, EventArgs e) { Form1_Paint(sender, pea); } PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Tạo đồng hồ điện tử public string GetTime() { string TimeInString = ""; int hour = DateTime.Now.Hour; int min = DateTime.Now.Minute; int sec = DateTime.Now.Second; if (hour < 10) { TimeInString = "0" + hour.ToString();...PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Vẽ số trên đồng hồ grfx.DrawString("4", new Font("Licenz Plate", 18.0f), Brushes.Black, 318, 267); grfx.DrawString("5", new Font("Licenz Plate", 18.0f), Brushes.Black, 263, 317); grfx.DrawString("7", new Font("Licenz... grfx.DrawString("10", new Font("Licenz Plate", 18.0f), Brushes.Black, 68, 119); grfx.DrawString("11", new Font("Licenz Plate", 18.0f), Brushes.Black, 120, 68); PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Vẽ các dấu chấm trên đồng hồ for (int i = 0; i < 360; i++) { int x = x0 + (int)Math.Round(150 * Math.Cos(i * Math.PI / 180)); int y = y0 - (int)Math.Round(150 * Math.Sin(i * Math.PI / 180)); if (i % 6 == 0 && i != 0 && i !=... sec.ToString(); else { TimeInString += ":" + sec.ToString(); } return TimeInString; } } PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Tạo Lịch Cập nhật thời gian cho MonthCalendar private void Form1_Load(object sender, EventArgs e) { monthCalendar1.TodayDate = DateTime.Now.Date; } PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Tạo âm thanh ticktac và âm thanh đóng form System.Media.SoundPlayer play = new System.Media.SoundPlayer(); play.SoundLocation... đóng form System.Media.SoundPlayer play = new System.Media.SoundPlayer(); play.SoundLocation = "dong cua.wav"; play.Play(); DialogResult result = MessageBox.Show("BẠN MUỐN THOÁT CHƯƠNG TRÌNH ?", "THÔNG BÁO ", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (Convert.ToString(result) == "Yes") { Application.Exit(); } else { System.Media.SoundPlayer play1 = new System.Media.SoundPlayer(); play1.SoundLocation .. .Đề Tài Tạo Đồng hồ TỔNG QUAN BÀI BÁO CÁO PHẦN I: GIỚI THIỆU TỔNG QUÁT VỀ ĐỒNG HỒ PHẦN II: XÂY DƯNG CHƯƠNG TRÌNH PHẦN III: KẾT LUẬN PHẦN I: GIỚI THIỆU TỔNG QUÁT VỀ ĐỒNG HỒ • Mục đích... grfx.FillEllipse(Brushes.Black , x - 2, y - 2, 6, 6); } PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Viết chữ lên đồng hồ grfx.DrawString("ĐH Lạc Hồng", new Font("Verdana", 17.0f), Brushes.Red, x0 - 80, y0 + 20); grfx.DrawString("Clock",... 15.0f, FontStyle.Italic), Brushes.Red, x0 - 80, y0 + 50); PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH Tạo ngày tháng năm đồng hồ int d = DateTime.Now.Day; int m = DateTime.Now.Month; int year = DateTime.Now.Year;

Ngày đăng: 17/12/2015, 11:21

Mục lục

    PHẦN I: GIỚI THIỆU TỔNG QUÁT VỀ ĐỒNG HỒ

    PHẦN II: XÂY DỰNG CHƯƠNG TRÌNH

Tài liệu cùng người dùng

Tài liệu liên quan