以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  求助:消失的动态控件去了哪里?……  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=107189)

--  作者:huangxueyao
--  发布时间:2017/9/22 20:55:00
--  求助:消失的动态控件去了哪里?……
\'建立符合状态的订单集合
Dim drs1 As List(of DataRow)
drs1 = DataTables("订单表").Select("订单状态 = \'PMC已确认\' and 实发量 is null ") \'注意此处空值的判断方式

Dim x As Integer = 1 \'名称后缀初始值
Dim y As Integer = 20 \'水平位置初始值
Dim z As Integer = 10 \'垂直位置初始值
Dim k As Single = e.Form.Controls("SplitContainer2").Panel2.Width \'分栏的宽度
\'遍历订单
For Each dr1 As DataRow In drs1
    \'查询对应的大类
    Dim dr1_1 As DataRow = DataTables("基础资料表").find("对应大类 = \'" & dr1("物料类别") & "\'")
    \'如果不符合,跳过
    If dr1_1("分拣部") <> vars("分拣类别") Then
        Continue For
        \'如果符合
    Else
        \'遍历控件判断是否已存在对应的控件
        Dim n As Integer = 0 \'定义变量判断是否存在对应控件
        For Each c As WinForm.Control In e.Form.Controls
            If Typeof c Is WinForm.Button Then \'判断控件是否是文本框
                Dim b As WinForm.Button = c \'使用特定类型的变量引用控件
                If b.Text = dr1("物料名称")
                    n = 1
                End If
            End If
        Next
        \'如果存在,则跳过
        If n = 1 Then
            Continue For
        Else                \'如果不存在,则新建控件
            Dim but As WinForm.Button
            but = e.Form.CreateControl("Button1" & x , ControlTypeEnum.Button)
            x=x+1
            If y + 200 > k Then \'这里的200等于宽度加Y的初始值20
                y = 20
                z = z + 70
                but.SetBounds(y, z, 180, 60) \'统一设置位置与大小(水平,垂直,宽度,高度)
            Else
                but.SetBounds(y, z, 180, 60) \'统一设置位置与大小(水平,垂直,宽度,高度)
                y = y+200
            End If
            MessageBox.show(dr1("物料名称"))
            but.Text = dr1("物料名称")  \'显示内容
            but.ReadOnly = True \'设置为只读
            but.TextAlign = HorizontalAlignment.Center \'对齐方式
            but.Font = New Font("宋体",16)
            but.BackColor = Color.white
            but.FlatStyle = FlatStyle.Flat
            but.BorderSize = 2
            but.BorderColor = Color.red
            \'but.Enabled = False
            e.Form.Controls("SplitContainer2").Panel2.AddControl(but)
        End If
    End If
Next


图片点击可在新窗口打开查看此主题相关图片如下:微信截图_20170922205323.png
图片点击可在新窗口打开查看

弹窗那里会出现5次,但是看图片,动态生成的空间只出现4个,剩余一个不知道哪里去了。

调整多次也没办法。


还有一个更诡异的



图片点击可在新窗口打开查看此主题相关图片如下:微信截图_20170922205555.png
图片点击可在新窗口打开查看

像上图,一共出现会出现12个结果,但是只显示10个,如果说是有两个在右边挡住了,但是为什么又会出现四行,而不是三行呢?

检查代码也不知道哪里搞错了

[此贴子已经被作者于2017/9/22 20:58:09编辑过]

--  作者:有点蓝
--  发布时间:2017/9/22 21:02:00
--  
上传具体实例看看

For Each c As WinForm.Control In e.Form.Controls
            If Typeof c Is WinForm.Button Then \'判断控件是否是文本框
                Dim b As WinForm.Button = c \'使用特定类型的变量引用控件
                If b.Text = dr1("物料名称")
                    n = 1
exit for
                End If
            End If
        Next

--  作者:huangxueyao
--  发布时间:2017/9/23 8:19:00
--  
测试了这个没有用。

[此贴子已经被作者于2017/9/25 11:24:48编辑过]