using System.Runtime.InteropServices;public class Form1 : System.Windows.Forms.Form
{[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public extern static long DeleteFile(String lpFileName);}
{[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public extern static long DeleteFile(String lpFileName);}
DeleteFile("c:\\ss.txt");
{
// 此方法用来设置当前获取焦点的控件,当然 .Net 中有更简单且直接的方法。
[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern IntPtr SetFocus(IntPtr hWnd);...private ListView lv;...private void button1_Click(object sender, EventArgs e)
{
if (this.lv != null)
SetFocus(this.lv.Handle); // 调用了 Win32API 来实现。// 简单的实现应该是 this.lv.Focus();
// 然而从本质上讲,此 .NET 方法也是调用了同样的 Win32API。}
}