471,347 Members | 1,777 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,347 software developers and data experts.

C# user.config confusion

Hi,

I have a windows form app which would benefit from the new application
settings support in VS2005.

Say that my form has a single textbox on it. When the form closes I would
like to save the text in that textbox as part as the user level application
settings. When the application restarts I would like that text to be
restored to the textbox.

Because I am not using a built-in property on my form does this mean that I
cannot use the designer to add my setting?

Or, do I *have* to create a custom class derived from
ApplicationSettingsBase and manage everything myself?

No matter how I approach this I cannot seem to get my settings to
"automagically" restore their values at app startup.

Any pointers would be greatly appreciated!

BT

Dec 30 '05 #1
7 2317
Just to provide more information:

Using the designer I added the following setting (using the designer)
Name: MySetting
Type: string
Scope: User
Value: Initial value

public Form1()
{
InitializeComponent();
// Load the data from user.config
textBox1.Text = Properties.Settings.Default.MySetting;
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Save any of my settings
Properties.Settings.Default.Save();
}

My problem is that textBox1.Text MySetting is not being restored correctly -
it always reverts to its "initial" value.

-BT
"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi,

I have a windows form app which would benefit from the new application
settings support in VS2005.

Say that my form has a single textbox on it. When the form closes I would
like to save the text in that textbox as part as the user level
application settings. When the application restarts I would like that
text to be restored to the textbox.

Because I am not using a built-in property on my form does this mean that
I cannot use the designer to add my setting?

Or, do I *have* to create a custom class derived from
ApplicationSettingsBase and manage everything myself?

No matter how I approach this I cannot seem to get my settings to
"automagically" restore their values at app startup.

Any pointers would be greatly appreciated!

BT

Dec 30 '05 #2
Ok, I figured it out - of course it was user error.

I was not updating the settings when the text of the textbox was actually
changed! :(

private void textBox1_TextChanged(object sender, EventArgs e)
{
Properties.Settings.Default.MySetting = textBox1.Text;
}
-BT

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP11.phx.gbl...
Just to provide more information:

Using the designer I added the following setting (using the designer)
Name: MySetting
Type: string
Scope: User
Value: Initial value

public Form1()
{
InitializeComponent();
// Load the data from user.config
textBox1.Text = Properties.Settings.Default.MySetting;
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Save any of my settings
Properties.Settings.Default.Save();
}

My problem is that textBox1.Text MySetting is not being restored
correctly - it always reverts to its "initial" value.

-BT
"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi,

I have a windows form app which would benefit from the new application
settings support in VS2005.

Say that my form has a single textbox on it. When the form closes I
would like to save the text in that textbox as part as the user level
application settings. When the application restarts I would like that
text to be restored to the textbox.

Because I am not using a built-in property on my form does this mean that
I cannot use the designer to add my setting?

Or, do I *have* to create a custom class derived from
ApplicationSettingsBase and manage everything myself?

No matter how I approach this I cannot seem to get my settings to
"automagically" restore their values at app startup.

Any pointers would be greatly appreciated!

BT


Dec 30 '05 #3
BT,

Why not use data binding and just bind the value of the textbox to the
MySetting property on the object? This would probably be much easier.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Ok, I figured it out - of course it was user error.

I was not updating the settings when the text of the textbox was actually
changed! :(

private void textBox1_TextChanged(object sender, EventArgs e)
{
Properties.Settings.Default.MySetting = textBox1.Text;
}
-BT

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP11.phx.gbl...
Just to provide more information:

Using the designer I added the following setting (using the designer)
Name: MySetting
Type: string
Scope: User
Value: Initial value

public Form1()
{
InitializeComponent();
// Load the data from user.config
textBox1.Text = Properties.Settings.Default.MySetting;
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Save any of my settings
Properties.Settings.Default.Save();
}

My problem is that textBox1.Text MySetting is not being restored
correctly - it always reverts to its "initial" value.

-BT
"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi,

I have a windows form app which would benefit from the new application
settings support in VS2005.

Say that my form has a single textbox on it. When the form closes I
would like to save the text in that textbox as part as the user level
application settings. When the application restarts I would like that
text to be restored to the textbox.

Because I am not using a built-in property on my form does this mean
that I cannot use the designer to add my setting?

Or, do I *have* to create a custom class derived from
ApplicationSettingsBase and manage everything myself?

No matter how I approach this I cannot seem to get my settings to
"automagically" restore their values at app startup.

Any pointers would be greatly appreciated!

BT



Dec 30 '05 #4
Thank you for the suggestion Nicholas and in fact I was just trying to
figure out the correct way to do that.

I am not sure how to create the binding between
Properties.Settings.Default.MySetting and the Text property of the textBox1
textbox.

textBox1.DataBindings.Add("Text", Properties.Settings, "Default.MySetting
");

Is this correct?

Thanks!
BT

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uU**************@TK2MSFTNGP11.phx.gbl...
BT,

Why not use data binding and just bind the value of the textbox to the
MySetting property on the object? This would probably be much easier.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Ok, I figured it out - of course it was user error.

I was not updating the settings when the text of the textbox was actually
changed! :(

private void textBox1_TextChanged(object sender, EventArgs e)
{
Properties.Settings.Default.MySetting = textBox1.Text;
}
-BT

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP11.phx.gbl...
Just to provide more information:

Using the designer I added the following setting (using the designer)
Name: MySetting
Type: string
Scope: User
Value: Initial value

public Form1()
{
InitializeComponent();
// Load the data from user.config
textBox1.Text = Properties.Settings.Default.MySetting;
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Save any of my settings
Properties.Settings.Default.Save();
}

My problem is that textBox1.Text MySetting is not being restored
correctly - it always reverts to its "initial" value.

-BT
"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi,

I have a windows form app which would benefit from the new application
settings support in VS2005.

Say that my form has a single textbox on it. When the form closes I
would like to save the text in that textbox as part as the user level
application settings. When the application restarts I would like that
text to be restored to the textbox.

Because I am not using a built-in property on my form does this mean
that I cannot use the designer to add my setting?

Or, do I *have* to create a custom class derived from
ApplicationSettingsBase and manage everything myself?

No matter how I approach this I cannot seem to get my settings to
"automagically" restore their values at app startup.

Any pointers would be greatly appreciated!

BT




Dec 30 '05 #5
BT,

Almost. I think you want:

textBox1.DataBindings.Add("Text", Properties.Settings.Default, "MySetting");
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Thank you for the suggestion Nicholas and in fact I was just trying to
figure out the correct way to do that.

I am not sure how to create the binding between
Properties.Settings.Default.MySetting and the Text property of the
textBox1 textbox.

textBox1.DataBindings.Add("Text", Properties.Settings, "Default.MySetting
");

Is this correct?

Thanks!
BT

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:uU**************@TK2MSFTNGP11.phx.gbl...
BT,

Why not use data binding and just bind the value of the textbox to the
MySetting property on the object? This would probably be much easier.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Ok, I figured it out - of course it was user error.

I was not updating the settings when the text of the textbox was
actually changed! :(

private void textBox1_TextChanged(object sender, EventArgs e)
{
Properties.Settings.Default.MySetting = textBox1.Text;
}
-BT

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP11.phx.gbl...
Just to provide more information:

Using the designer I added the following setting (using the designer)
Name: MySetting
Type: string
Scope: User
Value: Initial value

public Form1()
{
InitializeComponent();
// Load the data from user.config
textBox1.Text = Properties.Settings.Default.MySetting;
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Save any of my settings
Properties.Settings.Default.Save();
}

My problem is that textBox1.Text MySetting is not being restored
correctly - it always reverts to its "initial" value.

-BT
"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
> Hi,
>
> I have a windows form app which would benefit from the new application
> settings support in VS2005.
>
> Say that my form has a single textbox on it. When the form closes I
> would like to save the text in that textbox as part as the user level
> application settings. When the application restarts I would like that
> text to be restored to the textbox.
>
> Because I am not using a built-in property on my form does this mean
> that I cannot use the designer to add my setting?
>
> Or, do I *have* to create a custom class derived from
> ApplicationSettingsBase and manage everything myself?
>
> No matter how I approach this I cannot seem to get my settings to
> "automagically" restore their values at app startup.
>
> Any pointers would be greatly appreciated!
>
> BT
>
>
>



Dec 30 '05 #6
Thank you Nicholas - for YEARS you have been helping countless thousands of
developers and you are much appreciated.

BT

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:ub**************@TK2MSFTNGP10.phx.gbl...
BT,

Almost. I think you want:

textBox1.DataBindings.Add("Text", Properties.Settings.Default,
"MySetting");
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Thank you for the suggestion Nicholas and in fact I was just trying to
figure out the correct way to do that.

I am not sure how to create the binding between
Properties.Settings.Default.MySetting and the Text property of the
textBox1 textbox.

textBox1.DataBindings.Add("Text", Properties.Settings, "Default.MySetting
");

Is this correct?

Thanks!
BT

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:uU**************@TK2MSFTNGP11.phx.gbl...
BT,

Why not use data binding and just bind the value of the textbox to
the MySetting property on the object? This would probably be much
easier.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Ok, I figured it out - of course it was user error.

I was not updating the settings when the text of the textbox was
actually changed! :(

private void textBox1_TextChanged(object sender, EventArgs e)
{
Properties.Settings.Default.MySetting = textBox1.Text;
}
-BT

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP11.phx.gbl...
> Just to provide more information:
>
> Using the designer I added the following setting (using the designer)
> Name: MySetting
> Type: string
> Scope: User
> Value: Initial value
>
> public Form1()
> {
> InitializeComponent();
> // Load the data from user.config
> textBox1.Text = Properties.Settings.Default.MySetting;
> }
>
> private void Form1_FormClosing(object sender, FormClosingEventArgs e)
> {
> // Save any of my settings
> Properties.Settings.Default.Save();
> }
>
> My problem is that textBox1.Text MySetting is not being restored
> correctly - it always reverts to its "initial" value.
>
> -BT
>
>
> "Bit Twiddler" <bi***********@hotmail.com> wrote in message
> news:%2***************@tk2msftngp13.phx.gbl...
>> Hi,
>>
>> I have a windows form app which would benefit from the new
>> application settings support in VS2005.
>>
>> Say that my form has a single textbox on it. When the form closes I
>> would like to save the text in that textbox as part as the user level
>> application settings. When the application restarts I would like
>> that text to be restored to the textbox.
>>
>> Because I am not using a built-in property on my form does this mean
>> that I cannot use the designer to add my setting?
>>
>> Or, do I *have* to create a custom class derived from
>> ApplicationSettingsBase and manage everything myself?
>>
>> No matter how I approach this I cannot seem to get my settings to
>> "automagically" restore their values at app startup.
>>
>> Any pointers would be greatly appreciated!
>>
>> BT
>>
>>
>>
>
>



Dec 30 '05 #7
BT,

Thanks for the props. Much appreciated.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:uX**************@TK2MSFTNGP12.phx.gbl...
Thank you Nicholas - for YEARS you have been helping countless thousands
of developers and you are much appreciated.

BT

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:ub**************@TK2MSFTNGP10.phx.gbl...
BT,

Almost. I think you want:

textBox1.DataBindings.Add("Text", Properties.Settings.Default,
"MySetting");
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Thank you for the suggestion Nicholas and in fact I was just trying to
figure out the correct way to do that.

I am not sure how to create the binding between
Properties.Settings.Default.MySetting and the Text property of the
textBox1 textbox.

textBox1.DataBindings.Add("Text", Properties.Settings,
"Default.MySetting ");

Is this correct?

Thanks!
BT

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:uU**************@TK2MSFTNGP11.phx.gbl...
BT,

Why not use data binding and just bind the value of the textbox to
the MySetting property on the object? This would probably be much
easier.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bit Twiddler" <bi***********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
> Ok, I figured it out - of course it was user error.
>
> I was not updating the settings when the text of the textbox was
> actually changed! :(
>
> private void textBox1_TextChanged(object sender, EventArgs e)
> {
> Properties.Settings.Default.MySetting = textBox1.Text;
> }
> -BT
>
> "Bit Twiddler" <bi***********@hotmail.com> wrote in message
> news:O$**************@TK2MSFTNGP11.phx.gbl...
>> Just to provide more information:
>>
>> Using the designer I added the following setting (using the designer)
>> Name: MySetting
>> Type: string
>> Scope: User
>> Value: Initial value
>>
>> public Form1()
>> {
>> InitializeComponent();
>> // Load the data from user.config
>> textBox1.Text = Properties.Settings.Default.MySetting;
>> }
>>
>> private void Form1_FormClosing(object sender, FormClosingEventArgs e)
>> {
>> // Save any of my settings
>> Properties.Settings.Default.Save();
>> }
>>
>> My problem is that textBox1.Text MySetting is not being restored
>> correctly - it always reverts to its "initial" value.
>>
>> -BT
>>
>>
>> "Bit Twiddler" <bi***********@hotmail.com> wrote in message
>> news:%2***************@tk2msftngp13.phx.gbl...
>>> Hi,
>>>
>>> I have a windows form app which would benefit from the new
>>> application settings support in VS2005.
>>>
>>> Say that my form has a single textbox on it. When the form closes I
>>> would like to save the text in that textbox as part as the user
>>> level application settings. When the application restarts I would
>>> like that text to be restored to the textbox.
>>>
>>> Because I am not using a built-in property on my form does this mean
>>> that I cannot use the designer to add my setting?
>>>
>>> Or, do I *have* to create a custom class derived from
>>> ApplicationSettingsBase and manage everything myself?
>>>
>>> No matter how I approach this I cannot seem to get my settings to
>>> "automagically" restore their values at app startup.
>>>
>>> Any pointers would be greatly appreciated!
>>>
>>> BT
>>>
>>>
>>>
>>
>>
>
>



Dec 30 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by KennethBohman | last post: by
reply views Thread by Jim Heavey | last post: by
2 posts views Thread by Mark | last post: by
5 posts views Thread by Dean Slindee | last post: by
12 posts views Thread by Ben | last post: by
reply views Thread by dgk | last post: by
3 posts views Thread by Piotrekk | last post: by
reply views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.