以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 保存界面数据 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=134181) |
||||
-- 作者:ZJZK2018 -- 发布时间:2019/4/29 10:31:00 -- 保存界面数据 下面代码出错,如何调整?谢谢 \'\'======批量界面信息设置保存===== Dim pth As String = ProjectPath & "Syscm\\用户设置\\" \'设置保存路径 Dim nms() As String = {"Table1","Table2","Table3"} Dim nns() As String = {"TextBox1","TextBox2","TextBox3"} Dim str As String = "" Dim tbstr As String = "" Dim txtstr As String = "" For Each nm As String In nms tbstr &= nm & e.Form.Controls(nm).Table.GetColVisibleWidth() & chr(11) Next For Each nn As String In nns txtstr &= nn & e.Form.Controls(nn).Value & chr(11) Next str = tbstr & txtstr Dim dd As String = pth & e.Form.Name & ".txt" FileSys.WriteAllText(dd, str.Trim(chr(11)), False, Encoding.Default) 下面代码出错了: \'\'======批量界面设置数据提取===== Dim pth As String = ProjectPath & "Syscm\\用户设置\\" \'设置保存路径 Dim dd As String = pth & e.Form.Name & ".txt" Dim cvs() As String = FileSys.ReadAllText(dd,Encoding.Default).Split(chr(11)) Dim nms() As String = {"Table1","Table2","Table3","TextBox1","TextBox2","TextBox3"} If cvs.length = nms.length Then For i As Integer = 0 To nms.length - 1 If nms(i).Contains("Table") e.Form.Controls(nms(i)).Table.SetColVisibleWidth(cvs(i)) End If If nms(i).Contains("TextBox") e.Form.Controls(i).Value = cvs(i) End If Next End If [此贴子已经被作者于2019/4/29 10:34:10编辑过]
|
||||
-- 作者:有点甜 -- 发布时间:2019/4/29 12:38:00 --
请说明报什么错
|
||||
-- 作者:ZJZK2018 -- 发布时间:2019/4/29 13:05:00 -- .NET Framework 版本:2.0.50727.8800 Foxtable 版本:2019.4.12.1 错误所在事件:窗口,窗口3,AfterLoad 详细错误信息: 未设置对象变量或 With 块变量。
|
||||
-- 作者:有点甜 -- 发布时间:2019/4/29 13:18:00 -- 1、你给的例子无法测试啊。请说明如何测试,测试步骤写出来。
2、txt是不是没有发上来? |
||||
-- 作者:ZJZK2018 -- 发布时间:2019/4/29 13:31:00 -- 打开窗口“界面数据”
我的需求是: 1、关闭窗口时先保存窗口中的{"Table1","Table2","Table3"}和控件{"TextBox1","TextBox2","TextBox3"},并保存到同一个txt文件中。 2、打开窗口时提取各种参数到指定控件中。 [此贴子已经被作者于2019/4/29 14:18:38编辑过]
|
||||
-- 作者:有点甜 -- 发布时间:2019/4/29 14:56:00 -- \'\'======批量界面设置数据提取===== Dim pth As String = ProjectPath & "Syscm\\用户设置\\" \'设置保存路径 Dim dd As String = pth & e.Form.Name & ".txt" Dim cvs() As String = FileSys.ReadAllText(dd,Encoding.Default).Split(chr(11)) Dim nms() As String = {"Table1","Table2","Table3","TextBox1","TextBox2","TextBox3"} If cvs.length = nms.length Then For i As Integer = 0 To nms.length - 1 If nms(i).Contains("Table") e.Form.Controls(nms(i)).Table.SetColVisibleWidth(cvs(i)) End If If nms(i).Contains("TextBox") e.Form.Controls(nms(i)).Value = cvs(i) End If Next End If |
||||
-- 作者:ZJZK2018 -- 发布时间:2019/4/29 16:56:00 -- 1、AfterClose事件中 Dim pth As String = ProjectPath & "Syscm\\用户设置\\" If FileSys.DirectoryExists(pth) = False Then FileSys.CreateDirectory(pth) Else Dim str As String = "" Dim tbstr As String = "" Dim txtstr As String = "" Dim tbnms() As String Dim lst As New List(of String) For Each ctb As Object In e.Form.Controls If Typeof ctb Is WinForm.Table Then \'判断控件是否是Table If lst.Contains(ctb.Name) = False Then lst.Add(ctb.Name) End If End If Next tbnms = Lst.ToArray() \'将集合转换为数组 For Each tbnm As String In tbnms tbstr &= e.Form.Controls(tbnm).Table.GetColVisibleWidth & chr(11) \'返回一个字符串,包括显示的列及列宽信息 Next txtstr = e.Form.Controls("Chebox_sxs").Value & chr(11) str = tbstr & txtstr Dim pthtxt As String = pth & e.Form.Name & ".txt" FileSys.WriteAllText(pthtxt, str.Trim(chr(11)), False, Encoding.Default) \'向文本文件中写入内容 End If 2、AfterLoad \'\'======窗口表批量列宽设置提取===== Dim pth As String = ProjectPath & "Syscm\\用户设置\\" \'设置保存路径 If FileSys.DirectoryExists(pth) = False Then FileSys.CreateDirectory(pth) Else Dim pthtxt As String = pth & e.Form.Name & ".txt" If FileSys.FileExists(pthtxt) Then \'判断指定的文件是否存在 Dim cvs() As String = FileSys.ReadAllText(pthtxt,Encoding.Default).Split(chr(11)) \'读取文本文件的内容 Dim tbnms() As String Dim lst As New List(of String) For Each ct As Object In e.Form.Controls If Typeof ct Is WinForm.Table Then \'判断控件是否是Table If lst.Contains(ct.Name) = False Then lst.Add(ct.Name) End If End If Next tbnms = Lst.ToArray() \'将集合转换为数组 If cvs.Length = tbnms.Length Then For i As Integer = 0 To tbnms.Length - 1 e.Form.Controls(tbnms(i)).Table.SetColVisibleWidth(cvs(i)) Next End If End If End If 老师红色代码部份加了以后,如何在AfterLoad事件中提取Chebox_sxs的值? |
||||
-- 作者:有点甜 -- 发布时间:2019/4/29 18:34:00 -- 存放的内容,必须有规则才行,比如你可以这样定义规则
控件名,值@控件名,值@控件名,值
这样,你用@分割,得到每个控件名和值,然后再用,分割,即可。最后用比如
e.form.controls(控件名).value = 值 |