Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wonder if anyone can help me figure this out?

I have a Marquee which scrolls text on TV screens and is working ok. Thing is that I need the end user to be able to change certain aspects of it through a Windows Form. I've been trying to use the Visual Studio Settings (which save to an AppConfig.XML file) to save the users' settings.

The text, font name and font size all save and restore perfectly, but for some reason the font colour, which is a System.Drawing.Color type, is always wrong.

When I open the AppConfig.XML or AppConfig.EXE.XML files in an external editor, the colour variable is correct, but the program seems to be getting its data from somewhere else for only this one object....

This is the code I'm using on the form:

VB
Dim FontName As String = My.Settings.ScrollFontName
Dim FontSize As Integer = My.Settings.ScrollFontSize
Dim FS As New Font(FontName, CInt(FontSize / 2), FontStyle.Regular)
Dim FontColour As System.Drawing.Color = My.Settings.ScrollColour

ScrollerSetupLbl.ForeColor = FontColour
ScrollerSetupLbl.Font = FS
ScrollerSetupLbl.ScrollLeftToRight = False
ScrollerSetupLbl.MarqueeText = My.Settings.ScrollText


(In case you're wondering about why I'm dividing the font size in half, the scrollbar on the setup form is half the height of the scrollbar on the main screen.)

This is the AppConfig XML file:

XML
<?xml version="1.0" encoding="utf-8"?>

<configuration>
  <configSections>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section name="Secure_Kiosk.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <userSettings>
    <Secure_Kiosk.My.MySettings>
      <setting name="ScrollFontName" serializeAs="String">
        <value>Arial</value>
      </setting>
      <setting name="ScrollFontSize" serializeAs="String">
        <value>36</value>
      </setting>
      <setting name="ScrollColour" serializeAs="String">
        <value>DarkBlue</value>
      </setting>
      <setting name="ScrollText" serializeAs="String">
        <value>Test text here</value>
      </setting>
    </Secure_Kiosk.My.MySettings>
  </userSettings>
</configuration>


Note that the "ScrollColour" value is "DarkBlue". I've also tried "Black", "Gold" and "White", all of which are recognised colours for the System.Drawing.Color type, but it always just displays "Red", which was the first colour I tried when I was testing it. For some reason it seems "stuck" on that one regardless.

I've also tried saving a String type variable in the settings, and converting to a System.Drawing.Color type in the form code and got exactly the same thing. The first colour I set "sticks" and won't change. Even manually editing the config files doesn't work.

Any ideas?

Thanks.
Posted

In my opinion, introduction of Data Contract rendered application settings morally obsolete, but many did not notice the value of Data Contract approach.

Data Contract is just one method of Serialization, but most robust, non-intrusive and easy-to-use. Using the Data Contract based XML files is much better compared to application settings: no limitations, provisions for versioning and backup compatibility. Please see:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

Please see also my past answers:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^],
deseralize a json string array[^].

—SA
 
Share this answer
 
v2
Comments
djdynamix 8-Oct-12 17:16pm    
Thank you for your suggestions, Sergey. I'm relatively new to Object Oriented programming, so I'm finding some of the terminology a bit confusing. Could you possibly point me to something a bit more "for dummies" about Data Contracts and Serialization? Is there something like a simple "how to" guide on how to create and read those kinds of XML files, without having to wade through MSDN? Thanks.
Sergey Alexandrovich Kryukov 8-Oct-12 18:04pm    
I see no need for something more "for dummies". If you need "for dummies", you would better need "OOP for dummies" and ".NET for dummies", and then you would cope with regular way of getting to Data Contract. I don't know "how to", but this is not the field where "how to" is good for you. In general, avoid "how to" approach. You better need to understand.
--SA
Espen Harlinn 8-Oct-12 18:11pm    
Good idea :-D
Sergey Alexandrovich Kryukov 8-Oct-12 18:45pm    
Thank you, Espen.
--SA
djdynamix 8-Oct-12 20:27pm    
Sorry, both of you, but you're not being terribly helpful with comments like that. I'm not a complete noobie. On the contrary, I've completed several advanced projects in VB.Net, including multi-threaded apps and Windows Services. I am, however, a bit "behind the times" when it comes to stuff like XML. (I always relied on INI files, which are apparently now obsolete. I don't need "beginners' guides to programming", I just need to know, in terminology I can understand, a) What is a Data Contract? b) Why is Serialization an issue in XML, and c) How does any of this help me to store my users'`preferences? I'm afraid the MSDN documentation is way too over-complicated and seems to rely on the reader being familiar with half-a-dozen other long and complex documents relating to other parts of the XML language which I don't need to know and will never use.

All I need to do is save 4 user preferences and a text string in some sort of settings file in a way which is not due to become obsolete in the next couple of incarnations of the .Net Framework!
Have a look at: User Settings Applied[^]

Seems to do what you want ...

Best regards
Espen Harlinn
 
Share this answer
 
Comments
djdynamix 8-Oct-12 20:53pm    
Thanks Espen. I've had a quick scan, and I think the information I need will probably be in there somewhere. I'm going to download the accompanying code and read through the article properly. The problem I've found with this subject is that most of the XML information out there is "bloated", with "Data Grid Views" and all sorts of database and dataset calls which I simply don't need. I just wish someone would put a tutorial out there which just simply explains how to do with XML what we used to do with INI files and nothing more. To be honest, if I'd known it was going to be this convoluted, I'd just have stuck a few keys and values in the registry and written the text to a .TXT file!
Espen Harlinn 9-Oct-12 3:58am    
It is a bit convoluted, but it's also pretty flexible ...
Sergey Alexandrovich Kryukov 8-Oct-12 21:23pm    
Nice article, my 5, but I don't know what OP needs -- probably, due to denial of any considerable effort on his side. Having programming experience since 1974 and still being uncomfortable with pretty simple reading and understanding is something which is hard to fix in a short answer. I met a number of such cases, never knew anything which could help.
--SA
Espen Harlinn 9-Oct-12 3:58am    
Thank you, Sergey :-D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900