.net 2010 VB.NET Xml Winforms - 保留 MDI 子位置和状态
我知道已经有人问过类似的问题,但这是我的问题。
在 MDI WinForm 中,我想保存每个应用程序用户的每个子窗口位置和状态,这与登录的 Windows 用户不同。我的应用程序有自己的用户;所以我不会使用像 my.Settings... 等用户设置。
一种选择是直接读/写数据库,但我不喜欢访问数据库来处理像 Windows 位置这样琐碎的事情。优点是我可以通过用户工作的机器独立存储这些信息,无论她在哪里登录,她的偏好都会被记住。
我想要遵循的另一个选择是使用 Xml 将该信息存储在用户计算机本地的文件中。结构可能是这样的:
<form name="form name">
<Top>120</Top>
<Left>100</Left>
<State>0</State>
</form>
<form name="another form">
<Top>120</Top>
<Left>120</Left>
<State>1</State>
</form>
我很难理解这是如何做到的;也许使用 Linq to Xml?我发现我可以写一些简单的东西,例如
Dim formPos As XElement = _
<User><%= My.Application.connectedUser.id %>
<form1>
<Top>120</Top>
<Left>100</Left>
<State>0</State>
</form1>
<form2>
<Top>120</Top>
<Left>100</Left>
<State>0</State>
</form2>
</User>
但是:
1)如何动态填充xml选项:我想要
<User id="1">
而不是
转换为
2) 完成构建后如何编写 XElement它。我应该使用 XmlWriter.Create
吗?热衷于将 XElement 传递给它吗?
3)当Xml文件中已经有一个同名的节点时会发生什么,我想覆盖以前的用户设置(如果它们已经存在),但不追加到文件,也不重写整个文件,当然
谢谢。
I know something similar has already been asked, but here's my problem.
In a MDI WinForm I want to save each child window position and state, per application user, that is different by the logged in Windows user. My application has its own users; so I won't use the user settings like my.Settings... etc.
One option is to read/write directly to the database, but I don't like the idea to access the database for something so trivial as the windows positions. The plus is that I could store that information independently by the machine where the user works, wherever she logs in, her preferences will be remembered.
Another option, that I'd like to follow, is to use Xml to store that information in a file locally on the user's computer. The structure could be something like:
<form name="form name">
<Top>120</Top>
<Left>100</Left>
<State>0</State>
</form>
<form name="another form">
<Top>120</Top>
<Left>120</Left>
<State>1</State>
</form>
I'm having a hard time to understand how this could be done; maybe using Linq to Xml? I've found I can write something as simple as
Dim formPos As XElement = _
<User><%= My.Application.connectedUser.id %>
<form1>
<Top>120</Top>
<Left>100</Left>
<State>0</State>
</form1>
<form2>
<Top>120</Top>
<Left>100</Left>
<State>0</State>
</form2>
</User>
But:
1) How to dinamically fill the xml options: I want
<User id="1">
and not<User><%= My.Application.connectedUser.id %>
that translates to <User>1
2) How to write the XElement when finished building it. Should I use an XmlWriter.Create
? Hot to pass it the XElement?
3) What happens when in the Xml file there's already a node with the same name, I want to overwrite the previous user settings if they are already there, but not append to the file, nor rewrite the entire file, of course
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它可能对其他人有用:
It may be useful to someone else: