Visual Basic .NET支持动态属性……
点击次数:44 次 发布日期:2008-11-06 08:07:53 作者:源代码网
|
源代码网推荐 源代码网推荐 要看动态属性的例子,首先在Visual Basic中创建一个Windows应用程序。添加一个TextBox到默认窗体中;确认TextBox是被选中的,然后在属性窗口中定位Dynamic属性。 源代码网推荐 源代码网推荐 点击Advanced标签旁边的省略号按钮,打开一个对话框,该对话框中列出了TextBox所有的属性,选择Text属性,键映射框将会被激活。键映射决定了键储存在配置文件中的值。点击确定关闭对话框。 源代码网推荐 源代码网推荐 下面的代码是在InitializeComponent方法中产生的(位于Windows Form设计器产生代码区)。这段代码不能直接修改,只能使用属性窗口。 源代码网推荐 源代码网推荐 Dim configurationAppSettings As _ 源代码网推荐 System.Configuration.AppSettingsReader = _ 源代码网推荐 New System.Configuration.AppSettingsReader() 源代码网推荐 源代码网推荐 Me.TextBox1.Text = CType( _ 源代码网推荐 configurationAppSettings.GetValue("TextBox1.Text", _ 源代码网推荐 GetType(System.String)), String) 源代码网推荐 源代码网推荐 设置储存在一个名为app.cofig的XML格式的文件中。前面的示例代码所产生的XML代码如下: 源代码网推荐 源代码网推荐 <?xml version="1.0" encoding="Windows-1252"?> 源代码网推荐 <configuration> 源代码网推荐 <appSettings> 源代码网推荐 <!-- User application and configured property settings go here.--> 源代码网推荐 <!-- Example: <add key="settingName" value="settingValue"/> --> 源代码网推荐 <add key="TextBox1.Text" value="TextBox1" /> 源代码网推荐 </appSettings> 源代码网推荐 </configuration> 源代码网推荐 源代码网推荐 当应用程序被编译时,该文件被重命名为assembly.config,这里assembly是你的编译出的应用程序的名字。如果想改变这些值,根本没有必要重新编译程序,只要简单的编辑配置文件在其中修改成相应的值即可。 源代码网推荐 源代码网推荐 源代码网供稿. |
