Click here to Skip to main content
15,894,460 members

Problem storing Label Font Color in App Settings (VB.Net in VS2012)

djdynamix asked:

Open original thread
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.
Tags: Visual Basic, Visual Studio 2012

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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