无法在.net 3.5中保存应用程序设置

发布于 2024-07-16 13:15:47 字数 2560 浏览 5 评论 0原文

我正在创建一个应用程序,它使用用户范围在应用程序设置中存储基本的数据库连接信息,例如主机、用户、密码和默认数据库名称。

我将 .net 3.5 与 Visual Studio 2008 一起使用,

我将 4 个文本框放入用户控件中,并将它们的文本属性绑定到应用程序设置的各个属性。

// 
        // textBox_database
        // 
        this.textBox_database.Location = new System.Drawing.Point(103, 101);
        this.textBox_database.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
        this.textBox_database.Name = "textBox_database";
        this.textBox_database.Size = new System.Drawing.Size(255, 27);
        this.textBox_database.TabIndex = 5;
        this.textBox_database.Text = global::PHP_Code_Generator_2.Properties.Settings.Default.mysql_database;
        // 
        // textBox_password
        // 
        this.textBox_password.Location = new System.Drawing.Point(103, 69);
        this.textBox_password.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
        this.textBox_password.Name = "textBox_password";
        this.textBox_password.Size = new System.Drawing.Size(255, 27);
        this.textBox_password.TabIndex = 4;
        this.textBox_password.Text = global::PHP_Code_Generator_2.Properties.Settings.Default.mysql_password;
        this.textBox_password.UseSystemPasswordChar = true;
        // 
        // textBox_user
        // 
        this.textBox_user.Location = new System.Drawing.Point(103, 37);
        this.textBox_user.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
        this.textBox_user.Name = "textBox_user";
        this.textBox_user.Size = new System.Drawing.Size(255, 27);
        this.textBox_user.TabIndex = 7;
        this.textBox_user.Text = global::PHP_Code_Generator_2.Properties.Settings.Default.mysql_user;
        // 
        // textBox_server
        // 
        this.textBox_server.Location = new System.Drawing.Point(103, 5);
        this.textBox_server.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
        this.textBox_server.Name = "textBox_server";
        this.textBox_server.Size = new System.Drawing.Size(255, 27);
        this.textBox_server.TabIndex = 6;
        this.textBox_server.Text = global::PHP_Code_Generator_2.Properties.Settings.Default.mysql_server;

这些文本框将从用户那里获取用户数据以设置自己的数据库信息。 我有一个按钮,可以将修改后的信息保存回设置文件

private void button_save_Click(object sender, EventArgs e)
{
   Properties.Settings.Default.Save();
}

,但设计未保存。 有帮助吗?

问候, Anjan

致 Cyril:是的,我有代码在属性中分配修改后的值,但即使范围设置为“用户”,它也表示只读。 所以我删除了属性分配代码。 现在我把代码带回来并重新启动VS,它现在工作完美了:D愚蠢的我,我应该之前尝试这个旧程序。 谢谢西里尔。

I am creating a application that store basic database connection info like host,user, password and default database name in application settings using User Scope.

I am using .net 3.5 with Visual Studio 2008

I put 4 text boxes in a user control and bound their text property to the application settings individual properties.

// 
        // textBox_database
        // 
        this.textBox_database.Location = new System.Drawing.Point(103, 101);
        this.textBox_database.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
        this.textBox_database.Name = "textBox_database";
        this.textBox_database.Size = new System.Drawing.Size(255, 27);
        this.textBox_database.TabIndex = 5;
        this.textBox_database.Text = global::PHP_Code_Generator_2.Properties.Settings.Default.mysql_database;
        // 
        // textBox_password
        // 
        this.textBox_password.Location = new System.Drawing.Point(103, 69);
        this.textBox_password.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
        this.textBox_password.Name = "textBox_password";
        this.textBox_password.Size = new System.Drawing.Size(255, 27);
        this.textBox_password.TabIndex = 4;
        this.textBox_password.Text = global::PHP_Code_Generator_2.Properties.Settings.Default.mysql_password;
        this.textBox_password.UseSystemPasswordChar = true;
        // 
        // textBox_user
        // 
        this.textBox_user.Location = new System.Drawing.Point(103, 37);
        this.textBox_user.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
        this.textBox_user.Name = "textBox_user";
        this.textBox_user.Size = new System.Drawing.Size(255, 27);
        this.textBox_user.TabIndex = 7;
        this.textBox_user.Text = global::PHP_Code_Generator_2.Properties.Settings.Default.mysql_user;
        // 
        // textBox_server
        // 
        this.textBox_server.Location = new System.Drawing.Point(103, 5);
        this.textBox_server.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
        this.textBox_server.Name = "textBox_server";
        this.textBox_server.Size = new System.Drawing.Size(255, 27);
        this.textBox_server.TabIndex = 6;
        this.textBox_server.Text = global::PHP_Code_Generator_2.Properties.Settings.Default.mysql_server;

these text boxes will get user data from users to set their own database info. i have a button that saves the modified info back to the settings file

private void button_save_Click(object sender, EventArgs e)
{
   Properties.Settings.Default.Save();
}

but the design is not being saved. any help anyone?

regards,
Anjan

To Cyril: Yes i had the code to assign modified value in properties, but then even the scope was set to "User" it said readonly. So i removed the property assignment codes.
now i brought the code back and restarted VS, it works perfect now :D silly me, i should have try this old procedure before.
Thank you Cyril.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

邮友 2024-07-23 13:15:47

嗯...我记得几个月前在我的一个项目中遇到了同样的问题。 不幸的是我不记得我是如何解决它的。

一些检查...

  1. 尝试在项目属性中将属性范围设置为用户。
  2. 在您列出的代码中,我看不到您在哪里设置属性(只看到您检索属性)。 你在哪里设置的?

Hmm... I remember having the same problem a few months ago in one of my projects. Unfortunately I don't recall how I solved it.

Some checks...

  1. Try setting the property scope to User in the Project Properties.
  2. In the code you've listed I don't see where you set the property (only see you retrieving the property). Where have you set it?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文