随便放那儿[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]然后这里引用里面的函数
解决方案 »
- C# Settings.settings 是自动生成的吗?
- vs2010中文版和英文版能装在同一台机器上吗?
- Release 版
- c# table
- 版主:ADO.NET读取Excel数据丢失,直接导入也一样
- c#中怎样将一个类中 怎样声明 一个变量的引用,还有怎样将在构造函数参数中传入这个引用并赋值?给个例子
- ReadLine()读入的数字字符串没办法转换成int类型吗?
- 当WebRequest 的Uri中有中文时的问题
- 本人初识C#,请教些问题
- 关于使用TransactionScope进行数据更新的问题
- 怎样退出循环,通过在循环外部改变循环变量的值,循环时,外部按钮能够响应事件
- 如何把控制台程序制作成后台执行程序?????
[DllImport("KERNEL32", CharSet=System.Runtime.InteropServices.CharSet.Auto)]
public static extern int GetDriveType(string lpRootPathName);
[DllImport("gdi32.dll",EntryPoint="DeleteDC")]
public static extern IntPtr DeleteDC(IntPtr hDc);
>[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());
>}
>}
放在你的变量声明处就可以了的就如以下:
------------------------------------
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());
}
----------------------------------
{
[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());
}
>}