随便放那儿[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]然后这里引用里面的函数

解决方案 »

  1.   

    例如
    [DllImport("KERNEL32", CharSet=System.Runtime.InteropServices.CharSet.Auto)]
    public static extern int GetDriveType(string lpRootPathName);
      

  2.   

    如:
     [DllImport("gdi32.dll",EntryPoint="DeleteDC")]
      public static extern IntPtr DeleteDC(IntPtr hDc);
      

  3.   

    >namespace WinApp{
    >[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]//加这里>public class Form1 : System.Windows.Forms.Form
    >{
    >
    > private System.Windows.Forms.Button button1;
    > private const String saved_e = "..//xml//ellipses.xml";
    > private const String saved_l = "..//xml//lines.xml";
    > public Form1()
    >{
    >  InitializeComponent();
    >}
    >
    >protected override void Dispose( bool disposing )
    >{
    >  if( disposing )
    > {
    >    if (components != null) 
    >   {
    >     components.Dispose();
    >   }
    >   base.Dispose( disposing );
    >  }
    >}
    >[STAThread]
    >
    >static void Main() 
    >{
    >  Application.Run(new Form1());
    >}
    >}
      

  4.   

    [DllImport["gdi32.Dll"]
    放在你的变量声明处就可以了的就如以下:
    ------------------------------------
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Button button2;
    private System.Windows.Forms.Button button3;
    private System.Windows.Forms.TextBox textBox1; [DllImport("kernel32")]
    private static extern long WritePrivateProfileString(string section,
    string key,string val,string filePath);
    [DllImport("kernel32")]
    private static extern int GetPrivateProfileString(string section,
    string key,string def, StringBuilder retVal,
    int size,string filePath); public void IniWriteValue(string Section,string Key,string Value,string filepath)//对ini文件进行写操作的函数
    {
    WritePrivateProfileString(Section,Key,Value,filepath);
    } public string IniReadValue(string Section,string Key,string filepath)//对ini文件进行读操作的函数
    {
    StringBuilder temp = new StringBuilder(255);
    int i = GetPrivateProfileString(Section,Key,"",temp, 
    255, filepath);
    return temp.ToString(); } public string IniReadSection(string Key,string val,string filepath)//对ini文件进行读操作的函数
    {
    StringBuilder temp = new StringBuilder(255);
    int i = GetPrivateProfileString("",Key,val,temp, 
    255, filepath);
    return temp.ToString(); }
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows Form Designer generated code
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    }
    ----------------------------------
      

  5.   

    namespace WinApp{public class Form1 : System.Windows.Forms.Form
    {
      [DllImport("gdi32.dll",EntryPoint="DeleteDC")]
      public static extern IntPtr DeleteDC(IntPtr hDc); private System.Windows.Forms.Button button1;
     private const String saved_e = "..//xml//ellipses.xml";
     private const String saved_l = "..//xml//lines.xml";
     public Form1()
    {
      InitializeComponent();
    }protected override void Dispose( bool disposing )
    {
      if( disposing )
     {
        if (components != null) 
       {
         components.Dispose();
          DeleteDC(this.Handle);  //调用
       }
       base.Dispose( disposing );
      }
    }
    [STAThread]static void Main() 
    {
      Application.Run(new Form1());
    }
    >}