首页 > 开发 > 综合 > 正文

使用.INI文件为输入界面创建"动态帮助"

2024-07-21 02:25:00
字体:
来源:转载
供稿:网友
在c#编程中,某些情况下我们可能还会用到.ini文件。例如为一个输入界面创建“动态帮助”:

我们在输入界面下方设置一个标签,当用户将光标移动到每一个textbox或其他输入,选择框时,标签文字自动变换为该输入项的一些帮助信息。

ini文件是文本文件,由若干节(section)组成,在每个带括号的标题下面,是若干个关键词(key)及其对应的值(value)

  [section]

  key=value


我们的ini文件比较简单,文件名为:helpinfo.ini。
-----------------
[promptinfo]
yourtextbox = 请输入xxxxx信息。

-----------------

首先我们要用以下语句调用kernel32.dll

[dllimport ("kernel32")]
private static extern int getprivateprofilestring(string section, string key, string def, stringbuilder retval, int size, string filepath);


然后为输入项(如一个textbox)的enter事件编写一个回调方法

this.yourtextbox.enter += new system.eventhandler(this.conenter);
private void conenter(object sender, system.eventargs e)
{
string strpromptfile = directory.getcurrentdirectory() + "//helpinfo.ini";//获取ini文件所在的路径

string strclsname = sender.gettype().tostring().toupper();
if( strclsname.endswith("textbox") )
{
if(sender.equals(yourtextbox))
{
getprivateprofilestring("promptinfo", "yourtextbox" ,"",strpromptcontent,
1024, strpromptfile);
}
txthelpcontent.text = strpromptcontent.tostring();//txthelpcontent就是显示帮助信息的标签
}


菜鸟学堂:
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表