在应用程序设置中存储标签字体颜色的问题(VS2012中的VB.Net) [英] Problem storing Label Font Color in App Settings (VB.Net in VS2012)

查看:130
本文介绍了在应用程序设置中存储标签字体颜色的问题(VS2012中的VB.Net)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人可以帮我解决这个问题?



我有一个Marquee在电视屏幕上滚动文字并且工作正常。我需要最终用户能够通过Windows窗体更改它的某些方面。我一直在尝试使用Visual Studio设置(保存到AppConfig.XML文件)来保存用户的设置。



文本,字体名称和字体大小完全保存和恢复,但由于某种原因,字体颜色,即System.Drawing.Color类型,总是错误的。



当我打开外部编辑器中的AppConfig.XML或AppConfig.EXE.XML文件,颜色变量是正确的,但程序似乎只从这个对象的其他地方获取数据....



这是我在表单上使用的代码:



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





(如果你想知道为什么我将字体大小分成两半,设置表单上的滚动条是主屏幕上滚动条高度的一半。)



这是AppConfig XML文件:





(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"?>

<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>





请注意ScrollColour值是DarkBlue。我也试过Black,Gold和White,所有这些都是System.Drawing.Color类型的公认颜色,但它总是显示Red,这是我试用的第一种颜色正在测试它。出于某种原因,无论如何它似乎卡在那个。



我也尝试在设置中保存String类型变量,并转换为System.Drawing .Color类型在表单代码中得到了完全相同的东西。我设置的第一种颜色粘并且不会改变。即使手动编辑配置文件也行不通。



有什么想法吗?



谢谢。



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.

推荐答案

在我看来,数据合同的引入使应用程序设置在道德上已经过时,但许多人没有注意到Data Contract方法的价值。



数据合同只是序列化的一种方法,但最强大,非侵入性且易于使用。与应用程序设置相比,使用基于数据协定的XML文件要好得多:没有限制,版本控制和备份兼容性的规定。请参阅:

http://msdn.microsoft.com/en-us /library/ms733127.aspx [ ^ ]。



请参阅我过去的答案:

如何在表单应用程序中使用XML文件编写器和阅读器? [ ^ ],

创建属性文件... [ ^ ],

解析json字符串数组 [ ^ ]。



-SA
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


看看:应用的用户设置 [ ^ ]



好像做你想做的......



祝你好运

Espen Harlinn
Have a look at: User Settings Applied[^]

Seems to do what you want ...

Best regards
Espen Harlinn


这篇关于在应用程序设置中存储标签字体颜色的问题(VS2012中的VB.Net)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆