Click here to Skip to main content
12,755,095 members (37,778 online)

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:

        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 version="1.0" encoding="utf-8"?>

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

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?

Tags: VB, VB.NET, VS2012


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.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100