Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use VB.NET dynamic properties

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how to use VB.NET dynamic properties", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use VB.NET dynamic properties" this article.

Visual Basic .NET supports dynamic properties, which are stored in an application configuration file that will be read when the application executes. Using dynamic properties, you can change some property values without recompiling the application. You can use them to save database connection strings, application log information, or server connection information.

To see an example of the dynamic properties of VB.NET, first create a Windows application in Visual Basic. Add a TextBox to the default form; verify that TextBox is selected, and then locate the Dynamic property in the properties window.

Click the ellipsis button next to the Advanced tab to open a dialog box that lists all the properties of TextBox. Select the Text attribute and the key mapping box will be activated. The key mapping determines that the key stores the values in the configuration file. Click OK to close the dialog box.

The following code is generated in the InitializeComponent method (in the code generation area of the Windows Form designer). This code cannot be modified directly and can only be used in the properties window.

Dim configurationAppSettings

As _ _ System.Configuration.

AppSettingsReader = _ New

System.Configuration.

AppSettingsReader ()

Me.TextBox1.Text = CType

(_ configurationAppSettings.

GetValue ("TextBox1.Text"

_ GetType (System.String))

String)

The settings are stored in a file called app.cofig in XML format. The previous sample code produces the following XML code:

< ?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>

When the application is compiled, the file is renamed to assembly.config, where assembly is the name of your compiled application. If you want to change these values, there is no need to recompile the program at all, as long as you simply edit the configuration file and change it to the corresponding value.

The above is all the content of this article "how to use VB.NET dynamic properties". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report