Sesli Alarm Programı — Csharp
Soru :
Textbox’a girilen saate göre zamanı gelince müzik çalan ve girilen saate göre bilgisayarı kapatan programın csharp windows forms application kodlarını yazınız.
[code lang=”csharp”]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ÖdevAlarm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int a = 10;
int count = 0;
private void Form1_Load(object sender, EventArgs e)
{
label3.Text = DateTime.Now.ToLongTimeString();
timer1.Enabled = true;//www.gorselprogramlama.com
}
private void button1_Click(object sender, EventArgs e)
{
try
{
DateTime AlarmZamani = Convert.ToDateTime(textBox1.Text);
}
catch (Exception)
{
MessageBox.Show("Lütfen Geçerli bir zaman giriniz!!!");
textBox1.Focus();
textBox1.SelectAll();
return;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
label3.Text = DateTime.Now.ToLongTimeString();
if (label3.Text == textBox1.Text)
{
axWindowsMediaPlayer1.URL = Application.StartupPath + @"\Amon Amarth – Death In Fire.mp3";
timer1.Enabled = true;//www.gorselprogramlama.com
}
}
private void button3_Click(object sender, EventArgs e)
{
timer3.Enabled = false;
axWindowsMediaPlayer1.Ctlcontrols.stop();
timer2.Enabled = true;
}
private void timer2_Tick(object sender, EventArgs e)
{
if (label3.Text == textBox2.Text.ToString())
{
timer2.Enabled = false;//www.gorselprogramlama.com
System.Diagnostics.Process.Start("shutdown", "-f -s");
}
}
private void button4_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("shutdown", " -a");
}
private void button2_Click(object sender, EventArgs e)
{
a =10;
timer3.Enabled = true;
axWindowsMediaPlayer1.Ctlcontrols.stop();//www.gorselprogramlama.com
label2.Text = a.ToString() + " Saniye kaldı";
}
private void timer3_Tick(object sender, EventArgs e)
{
while (a==0)
{
axWindowsMediaPlayer1.Ctlcontrols.play();
timer1.Enabled = true;
timer3.Enabled = false;
label2.Text = "Kalkma Zamanı Geldi!\n" + count.ToString() +
". erteleme zamanı";
return;
}
a–;
label2.Text = a.ToString() + " Saniye kaldı";//www.gorselprogramlama.com
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text.Length == 2)
{
textBox1.Text += ":";
textBox1.SelectionStart = 3;
}
if (textBox1.Text.Length == 5)
{
textBox1.Text += ":";
textBox1.SelectionStart = 6;
}
if (textBox1.Text.Length == 8)
{
button1.Focus();
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (textBox2.Text.Length == 2)
{
textBox2.Text += ":";
textBox2.SelectionStart = 3;
}
if (textBox2.Text.Length == 5)
{
textBox2.Text += ":";
textBox2.SelectionStart = 6;
}
if (textBox2.Text.Length == 8)
{
button3.Focus();//www.gorselprogramlama.com
}
}
private void label2_Click(object sender, EventArgs e)
{
}
}
}
[/code]

