Foxtable(狐表)用户栏目专家坐堂 → [求助]自动排列控件间距


  共有2898人关注过本帖树形打印复制链接

主题:[求助]自动排列控件间距

帅哥哟,离线,有人找我吗?
有点甜
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/5/22 10:24:00 [显示全部帖子]

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:控件间距.table


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/5/23 9:29:00 [显示全部帖子]

以下是引用blsu33在2018/5/23 6:35:00的发言:
老师,
   后续排版是手工弄(增加列填写left top)还是代码调整呢?

例如 Lable 有4个字符 如经济类型 有两个字符的 如 性别  两个都是左对齐 
可是 对应的 位置 TEXTBOX 就不对齐了,怎么写代码能让界面控件 再好看些

 

你可以先给label赋值,然后得到每个label的width属性,取最大那个width的值,然后设置各个textbox的位置,即可。


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/5/23 21:32:00 [显示全部帖子]

不可以这样,必须先全部取出,然后再比较的。

 

或者,你表格那里可以加入辅助列,计算每个控件的标题的字符数,那就可以直接查到字符最大的了。


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/5/23 23:02:00 [显示全部帖子]

比如

 

Dim e = args(0)
Dim pnl = args(1)
Dim code As String = "dim frm = args(0)" & vbcrlf
code &= "dim pnl = args(1)" & vbcrlf
code &= "dim txt " & vbcrlf
Dim drs2 As List (of DataRow)=DataTables("控件类型").Select("c")
If drs2 IsNot Nothing Then
    For Each dr2 As DataRow In drs2
        code &= "txt=frm.CreateControl(" & """lb_" & dr2("pouttabcolcap") &  """, ControlTypeEnum.Label)" & vbcrlf
        code &= "pnl.addControl(txt)" & vbcrlf
        code &= "txt=frm.CreateControl(""kj_" & dr2("pouttabcolcap") & """, ControlTypeEnum." & dr2("bindingtype")  & ")" & vbcrlf
        code &= "pnl.addControl(txt)" & vbcrlf
    Next
End If
code &= "return txt"
MessageBox.Show(code)
Functions.remove("test")
Functions.Add("test",Code)
Functions.Complie()
Functions.Execute("test", e.form, pnl)
Dim h As Integer = (pnl.height-10) / math.Ceiling(drs2.count / 2)
Dim w As Integer = (pnl.width-10) / 2
Dim i As Integer = 0
Dim lablen As Integer=0
Dim len As Integer = 0
For Each dr3 As DataRow In drs2
    Dim lb As WinForm.Label = e.Form.Controls("lb_" & dr3("pouttabcolcap"))
    lb.AutoSize = True
    lb.text = dr3("pouttabcolcap") & ":"
    If lablen<lb.width Then
        lablen=lb.width
        len= Encoding.default.getbytes(dr3("pouttabcolcap")).length
    End If
Next
msgbox(lablen)
For Each dr3 As DataRow In drs2
    Dim lb As WinForm.Label = e.Form.Controls("lb_" & dr3("pouttabcolcap"))
    Dim kj As WinForm.control = e.Form.Controls("kj_" & dr3("pouttabcolcap"))
    kj.BindingField=dr3("pouttabcol")
    lb.top = 3+(i\2)*h
    lb.left = iif(i Mod 2 = 0, 5, w)
    lb.text = dr3("pouttabcolcap").padright(len-dr3("pouttabcolcap").length) & ":"
    kj.top = 3+(i\2)*h
    kj.left = iif(i Mod 2 = 0, 5, w) + lablen
    kj.width=180
    i += 1
Next


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/6/10 23:23:00 [显示全部帖子]

Dim e = args(0)
Dim pnl = args(1)
Dim code As String = "dim frm = args(0)" & vbcrlf
code &= "dim pnl = args(1)" & vbcrlf
code &= "dim txt " & vbcrlf
Dim drs2 As List (of DataRow)=DataTables("控件类型").Select("controlgzid is not null")
If drs2 IsNot Nothing Then
    For Each dr2 As DataRow In drs2
        code &= "txt=frm.CreateControl(" & """lb_" & dr2("pouttabcolcap") &  """, ControlTypeEnum.Label)" & vbcrlf
        code &= "pnl.addControl(txt)" & vbcrlf
        code &= "txt=frm.CreateControl(""kj_" & dr2("pouttabcolcap") & """, ControlTypeEnum." & dr2("bindingtype")  & ")" & vbcrlf
        code &= "pnl.addControl(txt)" & vbcrlf
    Next
End If
code &= "return txt"
MessageBox.Show(code)
Functions.remove("test")
Functions.Add("test",Code)
Functions.Complie()
Functions.Execute("test", e.form, pnl)
Dim h As Integer = (pnl.height-10) / math.Ceiling(drs2.count / 4)
Dim w As Integer = (pnl.width-10) / 4
Dim i As Integer = 0
Dim lablen As Integer=0
Dim len As Integer = 0
For Each dr3 As DataRow In drs2
    Dim lb As WinForm.Label = e.Form.Controls("lb_" & dr3("pouttabcolcap"))
    lb.AutoSize = True
    lb.text = dr3("pouttabcolcap") & ":"
    If lablen<lb.width Then
        lablen=lb.width
        len= Encoding.default.getbytes(dr3("pouttabcolcap")).length
    End If
Next
msgbox(lablen)
For Each dr3 As DataRow In drs2
    Dim lb As WinForm.Label = e.Form.Controls("lb_" & dr3("pouttabcolcap"))
    Dim kj As WinForm.control = e.Form.Controls("kj_" & dr3("pouttabcolcap"))
    kj.BindingField=dr3("pouttabcol")
    lb.top = 3+(i\4)*h
    lb.left = iif(i Mod 4 = 0, 5, w*(i Mod 4))
    lb.text = dr3("pouttabcolcap").padright(len-dr3("pouttabcolcap").length) & ":"
    kj.top = 3+(i\4)*h
    kj.left = iif(i Mod 4 = 0, 5, w*(i Mod 4)) + lablen
    kj.width=50
    i += 1
Next

 回到顶部