我做了一个坏报警电池笔记本电脑 [英] i make a bad alarm battery laptop
本文介绍了我做了一个坏报警电池笔记本电脑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
实际上我是新手,我想当我尝试放置if语句时我错了,我希望我的应用程序向我发送警报音乐当电池状态超过90%或低于20%时,结果是应用程序运行良好且音乐警报不好听。
我的代码:
命名空间 batrei_laptop_rev_2
{
public 部分 类 Form1:表单
{
public Form1 ()
{
InitializeComponent();
}
private void Form1_Load( object sender,EventArgs e)
{
timer1.Enabled = true ;
}
string musik;
private void timer1_Tick( object sender,EventArgs e)
{
PowerStatus status = SystemInformation.PowerStatus;
progressBarStatus.Value =( int )(status.BatteryLifePercent * 100 );
lblBatterLevel.Text = String .Format( {0}%,(status.BatteryLifePercent * 100 ));
if ((status.BatteryLifePercent * 100 )> 90 )
{
StatusText.Text = SEGERA CABUT CHARGE'NYA;
axWindowsMediaPlayer1.URL = musik;
}
其他 如果((status.BatteryLifePercent * 100 )< 60 )
{
StatusText.Text = LAPTOP PERLU DI CHARGE;
axWindowsMediaPlayer1.URL = musik;
}
}
私有 void button1_Click( object sender,EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
if (open.ShowDialog()== DialogResult.OK)
{
musik = open.FileName;
textBox1.Text = open.SafeFileName;
}
}
}
}
有人帮我请... 。
解决方案
命名空间 batrei_laptop_rev_2
{
public partial class Form1:Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load( object sender,EventArgs e)
{
timer1.Enabled = true ;
}
string musik;
private void timer1_Tick( object sender,EventArgs e)
{
PowerStatus status = SystemInformation.PowerStatus;
progressBarStatus.Value =( int )(status.BatteryLifePercent * 100 );
lblBatterLevel.Text = String .Format( {0}%,(status.BatteryLifePercent * 100 ));
if ((status.BatteryLifePercent * 100 )> 90 )
{
StatusText.Text = SEGERA CABUT CHARGE'NYA;
axWindowsMediaPlayer1.URL = musik;
}
其他 如果((status.BatteryLifePercent * 100 )< 60 )
{
StatusText.Text = LAPTOP PERLU DI CHARGE;
axWindowsMediaPlayer1.URL = musik;
}
axWindowsMediaPlayer1.openPlayer(musik); // 添加此行希望以便它可以正常工作。
}
私人 void button1_Click( object sender,EventArgs e)
{
OpenFileDialog open = new OpenFileDialog() ;
if (open.ShowDialog()== DialogResult.OK)
{
musik = open.FileName;
textBox1.Text = open.SafeFileName;
}
}
}
}
如有任何问题请告诉我。
- > M.U
hi all,
actually i am a newbie, i think i get wrong when i try to place the if statement, i wish my application send me an alert music when the status of battery more than 90% or less than 20%,
but the result is the application is running well and the music alert is bad to listen.
this my code:
namespace batrei_laptop_rev_2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
}
string musik;
private void timer1_Tick(object sender, EventArgs e)
{
PowerStatus status = SystemInformation.PowerStatus;
progressBarStatus.Value = (int)(status.BatteryLifePercent * 100);
lblBatterLevel.Text = String.Format("{0}%", (status.BatteryLifePercent * 100));
if ((status.BatteryLifePercent * 100) > 90)
{
StatusText.Text = "SEGERA CABUT CHARGE'NYA";
axWindowsMediaPlayer1.URL = musik;
}
else if ((status.BatteryLifePercent * 100) < 60)
{
StatusText.Text = "LAPTOP PERLU DI CHARGE";
axWindowsMediaPlayer1.URL = musik;
}
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
if(open.ShowDialog() == DialogResult.OK)
{
musik = open.FileName;
textBox1.Text = open.SafeFileName;
}
}
}
}
somebody help me please....
解决方案
namespace batrei_laptop_rev_2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { timer1.Enabled = true; } string musik; private void timer1_Tick(object sender, EventArgs e) { PowerStatus status = SystemInformation.PowerStatus; progressBarStatus.Value = (int)(status.BatteryLifePercent * 100); lblBatterLevel.Text = String.Format("{0}%", (status.BatteryLifePercent * 100)); if ((status.BatteryLifePercent * 100) > 90) { StatusText.Text = "SEGERA CABUT CHARGE'NYA"; axWindowsMediaPlayer1.URL = musik; } else if ((status.BatteryLifePercent * 100) < 60) { StatusText.Text = "LAPTOP PERLU DI CHARGE"; axWindowsMediaPlayer1.URL = musik; } axWindowsMediaPlayer1.openPlayer(musik);//add this line hope so it will work. } private void button1_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); if(open.ShowDialog() == DialogResult.OK) { musik = open.FileName; textBox1.Text = open.SafeFileName; } } } }
if any issue then let me know.
-> M.U
这篇关于我做了一个坏报警电池笔记本电脑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文