Windows Develop Bookmark and Share   
 index > Windows Forms General > MCTS Moc2547 Application Settings question
 

MCTS Moc2547 Application Settings question

Hello,

Are there some guys that also do study MCTS Moc2547 C#?
If so:
it's about the resource toolkit book C# example code snippet, page 132.

can someone tell me where 'Settings' in:

public Color BackColor{
get{return (Settings["BackColor"]);}
}
applies to?

I get a compile error:
'myApplicationSettingsExperiment02.Settings' is a 'type' but is used like a 'variable'

I search/read everything but cannot find it or is it a typo?
Or what object is ment by 'Settings'?

regards,

Henk

mshvw  Thursday, July 19, 2007 3:47 PM
Project + properties, Settings tab, add the BackColor setting.
nobugz  Thursday, July 19, 2007 6:03 PM
Try Properties.Settings.Default.BackColor.
nobugz  Thursday, July 19, 2007 4:19 PM
I allready tried.....

In intellisense 'Properties dot' shows no 'Settings' item.
But the nearest items shown in intellisense are 'SetReadOnly' and 'SyncRoot'
Even if I include 'using System.Configuration'.
It's all about a class MyUserSettings derived from ApplicationSettingsBase.

In my Form.cs the 'Properties dot' DOES show 'Settings' in intellisense.

I allready inclused all 'usings' from Form.cs in MyUserSettings.cs but to no avail.

So the cause of the problem must be searched elsewhere

Henk

mshvw  Thursday, July 19, 2007 5:59 PM
Project + properties, Settings tab, add the BackColor setting.
nobugz  Thursday, July 19, 2007 6:03 PM
If I use

myApplication.Properties.
then Settings is part of intellisense but when building again an error occors

Error 1 'myApplicationSettingsExperiment02.Properties.Settings' is a 'type', which is not valid in the given context

Somehow I'm misinterpreting things.

'Settings' is an IDE generated class:
----------------------------------------
namespace myApplicationSettingsExperiment02.Properties
internal sealed partial class Settings : global:: System.Configuration.ApplicationSettingsBase
----------------------------------------

So 'Settings["BackColor"]' seems to refer to this 'Settings' class item indexed by the BackColor item.

I wonder how a class must be defined so you can access it with a textual index.


mshvw  Friday, July 20, 2007 9:13 AM
We might not be talking about the same thing here. The ApplicationSettingsBase class has an indexer that allows you to retrieve a setting by name. Perhaps the exam code was not trying to use the auto-generated Properties.Settings class.
nobugz  Friday, July 20, 2007 12:11 PM
Well it turned out after contacting the helpdesk of the course-support that it is an error in the coursebook and it should be the keyword 'this' and not 'Settings'.

wrong:
return (Settings["BackColor"]);

okay:
return (this["BackColor"]);

thanks anyway


mshvw  Saturday, July 21, 2007 11:55 AM

You can use google to search for other answers

Custom Search

More Threads

• disable text formatting for button.text?
• PCMCIA with Windows boot
• ListBoxes transfering from 1 box to another
• RealTimeStylus C#
• windows listbox
• How to convert voice recognition to text
• COM interopt all STA?
• how to using same stored procedure in two SqlCommand same time
• Invoking events at correct thread
• windows change mode