Change settings with application scope during runtime

Source: Internet
Author: User
Tags change settings

I checked this information on the Internet. Someone used to rewrite or copy settings. designer. CS method to make it work, we know that this file is automatically generated by the system, so it is best not to do this.

Here is a simple and practical method. This method can change the value set in the application range at runtime, but cannot be saved! To save this example, a user-defined setting is provided. You can also use other methods. This method can also be applied to encryption, which is useful for database connection strings :).

Here is an example for illustration:
1. Create a window ApplicationProgram
2. Place a textbox and button on the form.
3. Add two configuration items in Solution Explorer. As follows:
Username application range
Username2 user range
4. Add a form load event and a button click event.
5,CodeAs follows:

Namespace Setting
{
Public Partial Class Form1: Form
{
Public Form1 ()
{
Initializecomponent ();
}

Private   Void Form1_load ( Object Sender, eventargs E)
{
Setting. properties. settings. Default [ " Username " ] = Setting. properties. settings. Default. username2;
Textbox1.text = Setting. properties. settings. Default. Username;
}

private void button#click ( Object sender, eventargs e)
{< br> setting. properties. settings. default. username2 = textbox1.text;
setting. properties. settings. default. save ();
}< BR >}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.