以编程方式更改对象属性 [英] programmatically change object property

查看:76
本文介绍了以编程方式更改对象属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式更改复选框的状态和下一个tume我运行的应用程序不会更改,例如。



How can I programmatically change the state of a check box and next tume I run application doesn't change eg.

checkbox1.checked = false





将改变复选框的状态但是下次程序运行它会恢复到设计时默认如何保持更改?如果是假的?

或者我必须使用带有指示符的文件,例如txt文件,当存在虚假存储文件中的var并读取并更改它时?



will changes the state of the checkbox but next time program runs it reverts to the design time default how can I keep it changed? eg false?
Or I have to use a file with an indicator eg a txt file when going false store a var in the file and read it and change it?

推荐答案

IMHO使用 My.Settings对象 [ ^ ]



看看这个例子:使用设置如何使用设置来保存信息之间的运行。 [ ^ ] < br $>


定义设置

项目 - >属性 - >设置



The best way IMHO is to use the My.Settings Object[^]

Take a look at this example: Using Settings How to use settings to preserve information between runs. [^]

Defining a Setting
Project -> Properties -> Settings

Module Module1
    Sub Main()
       Console.WriteLine("Number of times run  {0} ", My.Settings.NumberOfTimesRun)
       My.Settings.NumberOfTimesRun += 1
       Console.WriteLine("Number of times run  {0} ", My.Settings.NumberOfTimesRun)
    
       ' Save the settings
        My.Settings.Save()

   End Sub
End Module    


请参阅我对该问题的评论。



也许这是回答成功的奇怪方式问题;我不能确定你能理解这一点,但你需要先从一些事情开始。这个想法是:你正在使用的操作系统不是这样的 https:/ /en.wikipedia.org/wiki/Persistence_%28computer_science%29#Persistent_operating_systems [ ^ ]。



您真的需要了解您的操作系统的功能。现在,迟早,您将开始编写和阅读持久数据。所以,给你一个很大的警告:有些人试图在系统注册表中保留数据,这是一件非常糟糕的事情;有太多的应用程序已经在注册表中收集垃圾,在很大程度上系统开始停滞。在大多数情况下,我过去的答案解释了如何获得存储数据的好地方:

哪个更好:使用注册来存储设置或使用设置类 [ ^ ],

如何查找我的程序目录 [ ^ ]。



更多想法:

https://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx [< a href =https://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110 %29.aspxtarget =_ blanktitle =新窗口> ^ ],

https://msdn.microsoft.com/en-us/library/bb397750%28v=vs.110%29.aspx [<一个href =https://msdn.microsoft.com/en-us/library/bb397750%28v=vs.110%29.aspxtarget =_ blanktitle =New Window> ^ ]。



很抱歉,如果这些信息的很大一部分似乎超出你的想象。并非一切都是一次性的。



-SA
Please see my comment to the question.

Perhaps this is a weird way of answering such question; and I cannot sure you can understand that, but you need to start with something. The idea is: the OS you are using is not like this: https://en.wikipedia.org/wiki/Persistence_%28computer_science%29#Persistent_operating_systems[^].

You really need to learn what your OS does in general. Now, sooner or later, you will get to writing and reading persisting data. So, a big warning for you: some people try to persist data in system Registry, which is a really bad thing; there are too many applications already collecting trash in the registry, to such a great extent that the system starts stalling. My past answers explain how to get good place to store your data, in most cases:
which is better : use of registery in order to store setting or use of Settings class[^],
How to find my programs directory[^].

Some more ideas:
https://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/bb397750%28v=vs.110%29.aspx[^].

Sorry if big part of this information seems to be over your head. Not everything comes at once.

—SA


这篇关于以编程方式更改对象属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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