黑马程序员—WinForm带有历史信息的ComboBox

 

---------------------- Windows Phone 7手机开发.Net培训、期待与您交流! ----------------------


说到历史信息,就需要通过某种方法来保存历史信息。

常用的方法有,配置文件,注册表,数据库。

当数据量比较小时,用数据库就不划算了。

下面来看一下用ini配置文件来实现保存历史信息。

读写配置文件需要用到两个API函数

[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);


当需要保存信息的时候可以这样写

WritePrivateProfileString(Section, Key, Value, this.inipath);  //section是节名,key是键名,value是要写入的值,this.inipath是要写入的配置文件的路径

 

读取文件的时候

StringBuilder temp = new StringBuilder(500);
            int i = GetPrivateProfileString(Section, Key, "", temp, 500, this.inipath);
            return temp.ToString();



 这样通过对配置文件的读写就可以得到一个具有历史信息的ComboBox了

---------------------- Windows Phone 7手机开发.Net培训、期待与您交流! ----------------------详细请查看:http://net.itheima.com/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值