日期:2014-05-18 浏览次数:21056 次
using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace 喇叭响 { public partial class Form1 : Form { public enum BeepType { SimpleBeep = -1, IconAsterisk = 0x00000040, IconExclamation = 0x00000030, IconHand = 0x00000010, IconQuestion = 0x00000020, Ok = 0x00000000, } [DllImport("user32.dll")] public static extern bool MessageBeep(BeepType beepType); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { MessageBeep(BeepType.SimpleBeep); } } }
------解决方案--------------------
//使用MessageBeep(unit uType):需添加 using System.Runtime.InteropServices; public const int MB_ICONEXCLAMATION = 48; [DllImport("user32.dll")] public static extern bool MessageBeep(uint uType); MessageBeep( MB_ICONEXCLAMATION );
------解决方案--------------------
Console.Beep();//这一句就可以搞定了。