实例介绍
【实例简介】
【实例截图】
【核心代码】
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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 | 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; using System.Runtime.InteropServices; namespace SoundCalculator { public partial class Form1 : Form { public Form1() { InitializeComponent(); } [DllImport( "winmm.dll" , EntryPoint = "mciSendString" )] private static extern Int32 mciSendString(String lpstrCommand, String lpstrReturnString, Int32 uReturnLength, Int32 hwndCallback); [DllImport( "kernel32" )] private static extern int GetPrivateProfileString( string section, string key, string def, StringBuilder retVal, int size, string filePath); public static string [] VoxPath = new string [24]; string tem_Value = "" ; string tem_FileName = "" ; Int32 n = 0; public void GetVox() { StringBuilder temp = new StringBuilder(255); if (System.IO.File.Exists(Application.StartupPath "\\Tem_File.ini" ) == true ) { for ( int i = 0; i < VoxPath.Length; i ) { GetPrivateProfileString( "Vox" , i.ToString(), "数据读取错误。" , temp, 255, Application.StartupPath "\\Tem_File.ini" ); VoxPath[i] = temp.ToString(); } } } public void sound( string FileName) { if (FileName == null ) //如果文件为空 return ; //退出操作 if (FileName.IndexOf( " " ) == -1) //如果路径中没有空格 { if (tem_FileName.Length!=0) //如果有播放的文件 mciSendString( "close " tem_FileName, null , 0, 0); //关闭当前文件的播放 n=mciSendString( "open " FileName , null , 0 , 0); //打开要播放的文件 n=mciSendString( "play " FileName, null , 0, 0); //播放当前文件 tem_FileName = FileName; //记录播放文件的路径 } } private void pict_Back_Click( object sender, EventArgs e) { tem_Value = ((PictureBox)sender).AccessibleName; //获取当前按钮的标识 switch (tem_Value) { case "0" : num(tem_Value); sound(VoxPath[0]); break ; //实现按钮的语音功能 case "1" : num(tem_Value); sound(VoxPath[1]); break ; case "2" : num(tem_Value); sound(VoxPath[2]); break ; case "3" : num(tem_Value); sound(VoxPath[3]); break ; case "4" : num(tem_Value); sound(VoxPath[4]); break ; case "5" : num(tem_Value); sound(VoxPath[5]); break ; case "6" : num(tem_Value); sound(VoxPath[6]); break ; case "7" : num(tem_Value); sound(VoxPath[7]); break ; case "8" : num(tem_Value); sound(VoxPath[8]); break ; case "9" : num(tem_Value); sound(VoxPath[9]); break ; case " " : js(tem_Value); sound(VoxPath[10]); break ; case "-" : js(tem_Value); sound(VoxPath[11]); break ; case "*" : js(tem_Value); sound(VoxPath[12]); break ; case "/" : js(tem_Value); sound(VoxPath[13]); break ; case "=" : js(tem_Value); sound(VoxPath[14]); break ; case "C" : Aclose(); sound(VoxPath[15]); break ; case "CE" : ce(); sound(VoxPath[16]); break ; case "Back" : backspace(); sound(VoxPath[17]); break ; case "%" : bai(); sound(VoxPath[18]); break ; case "X" : ji(); sound(VoxPath[19]); break ; case "." : dian(); sound(VoxPath[20]); break ; case " -" : { zf(); if (Convert.ToInt32(textBox1.Text) > 0) //如果当前为正数 sound(VoxPath[21]); //实现正数发音 else sound(VoxPath[22]); //实现负数发音 break ; } case "Sqrt" : kfang(); sound(VoxPath[23]); break ; } textBox1.Select(textBox1.Text.Length, 0); } bool isnum = false ; double n1 = 0; string fu = "" ; double zong = 0; bool isdian = false ; public void num( string n) { if (isnum == true ) { if (textBox1.Text == "0." ) { textBox1.Text = textBox1.Text n; } else { textBox1.Text = n; } isnum = false ; } else { if (textBox1.Text == "0" ) { textBox1.Text = n; } else { textBox1.Text = textBox1.Text n; } } n1 = Convert.ToDouble(textBox1.Text); } public void dian() { bool isfirst = isfloor(); if ((isnum == true ) || (textBox1.Text == "0" )) { textBox1.Text = "0." ; } if ((isdian == false ) && (isfirst == true )) { textBox1.Text = "0." ; } else if (isdian == false ) { if (Convert.ToDouble(textBox1.Text) == 0) { textBox1.Text = "0." ; } else if (isfirst == true ) { textBox1.Text = textBox1.Text; } else { textBox1.Text = textBox1.Text "." ; } isdian = true ; } } public bool isfloor() { var int1 = Convert.ToDouble(textBox1.Text); var int2 = Math.Floor(int1); if (int1 > int2) { return true ; } else { return false ; } } public void ce() { zong = Convert.ToDouble(textBox1.Text); textBox1.Text = "0" ; isnum = true ; isdian = false ; } public void Aclose() { isdian = isnum = false ; ce(); fu = tem_base = "" ; zong = n1 = 0; } public bool isxiao( double n) { double int1 = Convert.ToSingle(n); double int2 = Math.Floor(int1); if (int1 > int2) { return true ; } else { return false ; } } string tem_base; public void js( string s) { double lin = Convert.ToSingle(n1); if ((s == "=" ) && (fu == "=" )) { if ((tem_base == " " ) || (tem_base == "-" ) || (tem_base == "*" ) || (tem_base == "/" )) { zong = eval(zong , tem_base , lin); if (isxiao(zong) == true ) { textBox1.Text = Math.Round(zong, 4).ToString(); } else { textBox1.Text = zong.ToString(); } } } else if ((fu == "=" ) && (s == ( "*" ) || s == ( "/" ) || s == ( " " ) || s == ( "-" ))) { if (isxiao(zong) == true ) { textBox1.Text = Math.Round(zong, 4).ToString(); } else { textBox1.Text = zong.ToString(); } tem_base = fu; fu = s; } else { if (isnum && fu != "=" ) { if ( " " == fu) zong = eval(zong , fu , lin); else if ( "-" == fu) zong = eval(zong , fu , lin); else if ( "/" == fu) zong = eval(zong , fu , lin); else if ( "*" == fu) zong = eval(zong , fu , lin); else if ( "" == fu) zong = lin; if (isxiao(zong) == true ) { textBox1.Text = Math.Round(zong, 4).ToString(); } else { textBox1.Text = zong.ToString(); } tem_base = fu; fu = s; } else { if ( " " == fu) zong = lin; else if ( "-" == fu) zong = zong - lin; else if ( "/" == fu) zong /= lin; else if ( "*" == fu) zong *= lin; else zong = lin; if (isxiao(zong) == true ) { textBox1.Text = Math.Round(zong, 4).ToString(); } else { textBox1.Text = zong.ToString(); } tem_base = fu; fu = s; } } isnum = true ; } public void bai() { textBox1.Text = ((Convert.ToDouble(textBox1.Text) / 100) * Convert.ToDouble(zong)).ToString(); isdian = false ; } public void kfang() { if (textBox1.Text != "0" || textBox1.Text != "" ) { textBox1.Text = Math.Sqrt(Convert.ToDouble(textBox1.Text)).ToString(); isnum = true ; isdian = false ; } } public void zf() { double pp = Convert.ToDouble(textBox1.Text); if (pp > 0) { textBox1.Text = "-" pp; } if (pp < 0) { textBox1.Text = Math.Abs(pp).ToString(); } } public void ji() { double pp = Convert.ToDouble(textBox1.Text); textBox1.Text = Convert.ToDouble(1 / pp).ToString(); isnum = true ; isdian = false ; } public void backspace() { var bstr = textBox1.Text; if (bstr != "0" ) { string isabs = (Math.Abs(Convert.ToDouble(bstr)).ToString()); if ((bstr.Length == 1) || (isabs.Length == 1)) { textBox1.Text = "0" ; isdian = false ; } else { textBox1.Text = bstr.Substring(0, bstr.Length - 1); } } } public double eval( double n1, string sign, double n2) { switch (sign) { case "-" : return n1 - n2; case " " : return n1 n2; case "*" : return n1 * n2; case "/" : return n1 / n2; } return 0; } private void panel1_Paint( object sender, PaintEventArgs e) { } private void ToolS_Vox_Click( object sender, EventArgs e) { switch (Convert.ToInt32(((ToolStripMenuItem)sender).Tag.ToString())) { case 0: { Form2 Frm_2 = new Form2(); if (Frm_2.ShowDialog() == DialogResult.OK) { GetVox(); } break ; } case 1: Close(); break ; } } private void Form1_Load( object sender, EventArgs e) { GetVox(); } private void pict_Back_MouseEnter( object sender, EventArgs e) { SetButton(sender, false ); } private void pict_Back_MouseLeave( object sender, EventArgs e) { SetButton(sender, true ); } public void SetButton( object sender, bool b) //b为false时变色 { ((PictureBox)sender).Image = null ; tem_Value = ((PictureBox)sender).AccessibleName; switch (tem_Value) { case "0" : if (b) ((PictureBox)sender).Image = Properties.Resources._0; else ((PictureBox)sender).Image = Properties.Resources._0_1; break ; case "1" : if (b) ((PictureBox)sender).Image = Properties.Resources._1; else ((PictureBox)sender).Image = Properties.Resources._1_1; break ; case "2" : if (b) ((PictureBox)sender).Image = Properties.Resources._2; else ((PictureBox)sender).Image = Properties.Resources._2_1; break ; case "3" : if (b) ((PictureBox)sender).Image = Properties.Resources._3; else ((PictureBox)sender).Image = Properties.Resources._3_1; break ; case "4" : if (b) ((PictureBox)sender).Image = Properties.Resources._4; else ((PictureBox)sender).Image = Properties.Resources._4_1; break ; case "5" : if (b) ((PictureBox)sender).Image = Properties.Resources._5; else ((PictureBox)sender).Image = Properties.Resources._5_1; break ; case "6" : if (b) ((PictureBox)sender).Image = Properties.Resources._6; else ((PictureBox)sender).Image = Properties.Resources._6_1; break ; case "7" : if (b) ((PictureBox)sender).Image = Properties.Resources._7; else ((PictureBox)sender).Image = Properties.Resources._7_1; break ; case "8" : if (b) ((PictureBox)sender).Image = Properties.Resources._8; else ((PictureBox)sender).Image = Properties.Resources._8_1; break ; case "9" : if (b) ((PictureBox)sender).Image = Properties.Resources._9; else ((PictureBox)sender).Image = Properties.Resources._9_1; break ; case " " : if (b) ((PictureBox)sender).Image = Properties.Resources.Add; else ((PictureBox)sender).Image = Properties.Resources.Add1; break ; case "-" : if (b) ((PictureBox)sender).Image = Properties.Resources.Decr; else ((PictureBox)sender).Image = Properties.Resources.Decr1; break ; case "*" : if (b) ((PictureBox)sender).Image = Properties.Resources.Ride; else ((PictureBox)sender).Image = Properties.Resources.Ride1; break ; case "/" : if (b) ((PictureBox)sender).Image = Properties.Resources.Remove; else ((PictureBox)sender).Image = Properties.Resources.Remove1; break ; case "=" : if (b) ((PictureBox)sender).Image = Properties.Resources.Amound; else ((PictureBox)sender).Image = Properties.Resources.Amound1; break ; case "C" : if (b) ((PictureBox)sender).Image = Properties.Resources.c; else ((PictureBox)sender).Image = Properties.Resources.c1; break ; case "CE" : if (b) ((PictureBox)sender).Image = Properties.Resources.ce; else ((PictureBox)sender).Image = Properties.Resources.ce1; break ; case "Back" : if (b) ((PictureBox)sender).Image = Properties.Resources.back; else ((PictureBox)sender).Image = Properties.Resources.back1; break ; case "%" : if (b) ((PictureBox)sender).Image = Properties.Resources.Hund; else ((PictureBox)sender).Image = Properties.Resources.Humd1; break ; case "X" : if (b) ((PictureBox)sender).Image = Properties.Resources.Deno; else ((PictureBox)sender).Image = Properties.Resources.Deno1; break ; case "." : if (b) ((PictureBox)sender).Image = Properties.Resources.Dot; else ((PictureBox)sender).Image = Properties.Resources.Dot1; break ; case " -" : if (b) ((PictureBox)sender).Image = Properties.Resources.Bear; else ((PictureBox)sender).Image = Properties.Resources.Bear1; break ; case "Sqrt" : if (b) ((PictureBox)sender).Image = Properties.Resources.sqrt; else ((PictureBox)sender).Image = Properties.Resources.sqrt1; break ; } } private void textBox1_TextChanged( object sender, EventArgs e) { } } } |
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论