C# winform 创建,修改,删除 ini配置文件

using System;

using System.Collections.Generic;

using System.Text;

using System.Runtime.InteropServices;

 

namespace EmailCustomer

{

    class IniFile

    {

        private string path;

 

        ///   <summary> 

        ///   实例初始化为指定路径的INI文件。 

        ///   </summary> 

        ///   <param   name= "path "> INI文件路径。 </param> 

        public IniFile(string path)

        {

            this.path = path;

        }

 

        ///   <summary> 

        ///   获取INI文件的路径。 

        ///   </summary> 

        public string Path

        {

            get

            {

                return path;

            }

        }

 

        ///   <summary> 

        ///   读取指定小节下指定条目的字符串。 

        ///   </summary> 

        ///   <param   name= "sectionName "> 欲在其中查找条目的小节名称。这个字串不区分大小写。 </param> 

        ///   <param   name= "keyName "> 欲获取的项名或条目名。这个字串不区分大小写。 </param> 

        ///   <param   name= "defaultValue "> 指定的条目没有找到时返回的默认值。 </param> 

        ///   <returns> 指定小节下指定条目的字符串。 </returns> 

        ///   <remarks> 如果sectionName为null,则返回所有小节的列表,如果keyName为null,指定小节所有项的列表。 </remarks> 

        public string ReadString(string sectionName, string keyName, string defaultValue)

        {

            const int MAXSIZE = 255;

            StringBuilder temp = new StringBuilder(MAXSIZE);

            GetPrivateProfileString(sectionName, keyName, defaultValue, temp, 255, this.path);

            return temp.ToString();

        }

 

        public void WriteString(string sectionName, string keyName, string value)

        {

            WritePrivateProfileString(sectionName, keyName, value, this.path);

        }

 

        public int ReadInteger(string sectionName, string keyName, int defaultValue)

        {

            return GetPrivateProfileInt(sectionName, keyName, defaultValue, this.path);

        }

 

        public void WriteInteger(string sectionName, string keyName, int value)

        {

            WritePrivateProfileString(sectionName, keyName, value.ToString(), this.path);

        }

 

        public bool ReadBoolean(string sectionName, string keyName, bool defaultValue)

        {

            int temp = defaultValue ? 1 : 0;

            int result = GetPrivateProfileInt(sectionName, keyName, temp, this.path);

            return (result == 0 ? false : true);

        }

 

        public void WriteBoolean(string sectionName, string keyName, bool value)

        {

            string temp = value ? "1 " : "0 ";

            WritePrivateProfileString(sectionName, keyName, temp, this.path);

        }

 

        ///   <summary> 

        ///   删除这个项现有的字串。 

        ///   </summary> 

        ///   <param   name= "sectionName "> 要设置的项名或条目名。这个字串不区分大小写。 </param> 

        ///   <param   name= "keyName "> 要删除的项名或条目名。这个字串不区分大小写。 </param> 

        public void DeleteKey(string sectionName, string keyName)

        {

            WritePrivateProfileString(sectionName, keyName, null, this.path);

        }

 

        ///   <summary> 

        ///   删除这个小节的所有设置项。 

        ///   </summary> 

        ///   <param   name= "sectionName "> 要删除的小节名。这个字串不区分大小写。 </param> 

        public void EraseSection(string sectionName)

        {

            WritePrivateProfileString(sectionName, null, null, this.path);

        }

 

        [DllImport("kernel32")]

        public static extern int WritePrivateProfileString(string lpApplicationName, string lpKeyName, string lpString, string lpFileName);

        [DllImport("kernel32")]

        public static extern int GetPrivateProfileInt(string lpApplicationName, string lpKeyName, int nDefault, string lpFileName);

        [DllImport("kernel32")]

        public static extern int GetPrivateProfileString(string lpApplicationName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);

    }

}

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用AutoCAD的COM接口在C# WinForm创建DWG文件并绘制圆形。下面是一些基本的步骤: 1. 添加对AutoCAD的引用 在Visual Studio中,打开项目并在项目中引用AutoCAD COM组件。在“解决方案资源管理器”中,右键单击“引用”并选择“添加引用”选项。在“COM”选项卡中,选择“Autodesk AutoCAD 20xx Type Library”(其中“20xx”是AutoCAD的版本号)并单击“确定”。 2. 创建AutoCAD应用程序对象 使用以下代码创建AutoCAD应用程序对象: ``` using Autodesk.AutoCAD.Interop; using Autodesk.AutoCAD.Interop.Common; AcadApplication acadApp = new AcadApplication(); ``` 3. 创建新的DWG文件 使用以下代码创建新的DWG文件: ``` AcadDocument acadDoc = acadApp.Documents.Add(""); ``` 4. 绘制圆形 使用以下代码在新的DWG文件中绘制圆形: ``` AcadCircle circle = acadDoc.ModelSpace.AddCircle(new double[] {0, 0, 0}, 5); ``` 其中,第一个参数是圆心坐标,第二个参数是圆的半径。 5. 保存DWG文件 使用以下代码保存DWG文件: ``` acadDoc.SaveAs(@"D:\Drawing1.dwg"); ``` 完整的C#代码如下: ``` using Autodesk.AutoCAD.Interop; using Autodesk.AutoCAD.Interop.Common; AcadApplication acadApp = new AcadApplication(); AcadDocument acadDoc = acadApp.Documents.Add(""); AcadCircle circle = acadDoc.ModelSpace.AddCircle(new double[] {0, 0, 0}, 5); acadDoc.SaveAs(@"D:\Drawing1.dwg"); ``` 这样就可以在C# WinForm中使用AutoCAD COM接口创建DWG文件并绘制圆形了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值