以下是Windows编程下窗体闪烁的代码,请在需要注释的地方作详细注释:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices; //这句需要注释
namespace Example
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("User32")] //这句需要注释
public static extern bool FlashWindow(IntPtr hWnd,bool bInvert); //这句需要注释
private void button1_Click(object sender, EventArgs e)
{
int MyCount,MyTimes,MyTime;
try
{
MyTimes=System.Convert.ToInt16(this.textBox1.Text);
MyTime=System.Convert.ToInt16(this.textBox2.Text);
for(MyCount=0;MyCount<MyTimes;MyCount++)
{
FlashWindow(this.Handle,true); //这句需要注释
System.Threading.Thread.Sleep(MyTime);
}
}
catch(Exception MyEx)
{
System.Windows.Forms.MessageBox.Show(MyEx.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
} private void textBox2_TextChanged(object sender, EventArgs e)
{ } private void Form1_Load(object sender, EventArgs e)
{ }
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices; //这句需要注释
namespace Example
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("User32")] //这句需要注释
public static extern bool FlashWindow(IntPtr hWnd,bool bInvert); //这句需要注释
private void button1_Click(object sender, EventArgs e)
{
int MyCount,MyTimes,MyTime;
try
{
MyTimes=System.Convert.ToInt16(this.textBox1.Text);
MyTime=System.Convert.ToInt16(this.textBox2.Text);
for(MyCount=0;MyCount<MyTimes;MyCount++)
{
FlashWindow(this.Handle,true); //这句需要注释
System.Threading.Thread.Sleep(MyTime);
}
}
catch(Exception MyEx)
{
System.Windows.Forms.MessageBox.Show(MyEx.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
} private void textBox2_TextChanged(object sender, EventArgs e)
{ } private void Form1_Load(object sender, EventArgs e)
{ }
}
}
下面是方法的实现调用必须有 [DllImport("User32")] //这句需要注释
进行标识
[DllImport("User32")] 加载这个dll
调用public static extern bool FlashWindow(IntPtr hWnd,bool bInvert); 这个函数