按名称访问程序设置
我正在用 C# 编写一个程序。该程序控制一个物理滤镜轮,该滤镜轮具有可互换的轮子 A 至 H。每个轮子可容纳 8 个滤镜。我希望用户能够为每个轮子中的每个过滤器存储友好名称(总共 64 个)。该设备和程序能够识别车轮 ID (AH) 和过滤器位置 (1-8),因此存储这 64 个名称并能够通过 ID 和 POS 引用它们的最佳方式是什么。我可以为每个用户创建一个用户设置,但存在两个问题:1)登录到计算机的每个用户的名称都不相同(我认为),2)以便以编程方式访问特定名称我必须使用一个巨大的 case 语句。或者有没有办法通过名称访问设置?像这样..?
char WheelID = 'A';
int FilterPos = 4;
NewName = "FriendlyName";
string SettingIWant = WheelID.ToString() + FilterPos.ToString();
Properties.Settings[SettingIWant].Text = NewName;
I am writing a program in C#. The program controls a physical filter wheel which has interchangable wheels A through H. Each wheel can hold 8 filters. I want the user to be able to store friendly names for each filter in each wheel (64 total). The device and program are capable of identifying the wheel ID(A-H) and filter position (1-8) so what is the best way to store these 64 names and be able to reference them by the ID and POS. I could create a user setting for each one but there are two problems with that: 1) The names would not be the same for every user that logs onto the machine(i think), and 2) in order to access the specific names programmatically I have to use a HUGE case statement. Or is there a way to access settings by the name? like this..?
char WheelID = 'A';
int FilterPos = 4;
NewName = "FriendlyName";
string SettingIWant = WheelID.ToString() + FilterPos.ToString();
Properties.Settings[SettingIWant].Text = NewName;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好吧,我只是愚蠢,忽略了这种访问设置的方式......
它工作得很好。唯一的问题是每个用户存储的值并不相同,但他们只需要处理这个问题!
Ok, I was just dumb and overlooked this way accessing the settings...
It works just fine. The only issue is the stored values won't be the same for every user but they will just have to deal with that!
好吧,您可以采用数据库方法。
“内存中”的解决方案是字典。
Ant 然后您可以使用括号语法访问数据
Well, you could take the database approach.
An "in memory" solution, would be Dictionaries.
Ant then you can access the data using bracket syntax
当然有。只需覆盖
[]
运算符即可。Sure there is. Just override the
[]
operator.好的。我只是做了一些最小的研究,这就是我认为你想做的。
首先,实现 Rodrigo Garcia 的 Dicitonary 事物,但使用 System.Collections.Specialized.StringDictionary 除外。这是可以添加到设置文件中的类型之一。
设置应用程序设置时,如果列表中没有看到“类型”,请选择“浏览...”。
如果集合发生变化,请确保始终写出更改!
OK. I just did some minimal research and here's what I think you want to do.
First, implement Rodrigo Garcia's Dicitonary thing, except use
System.Collections.Specialized.StringDictionary
. This is one of the types that can be added to a settings file.When setting up your application settings, under Type, select "Browse..." if you don't see it in the list.
And make sure you always write the changes out, if the collection changes!