e.Form.StopRedraw() '停止绘制窗口
Dim s As String =
e.Form.Controls("查询日期").Value
'If s >= Date.Today() Then
For Each pg As
WinForm.TabPage In e.Form.Controls("TabControl1").TabPages
If pg.Text =
"全部0" Then
Dim lbl11 As
WinForm.Button
Dim Value1 As String =
DataTables("分类表").GetComboListString("产品名称", "[日期] =
#" & s & "#", "排序号") '排序:
Dim sps1() As Char = {"|"}
Dim Names1() As String =
Value1.Split(sps1)
Dim s1 As Integer = 10 '与左边距离
Dim t1 As Integer = 10 '与上边距离
For i1 As Integer = 0 To
Names1.length - 1
If i1
<> 0 Then
If i1 Mod 4 = 0 Then '如果1行显示3个控件
s1 = 10
t1 = t1 + 45 '调整控件纵向间距(30*15)
Else
s1 = s1 + 105 ''调整控件横向间距(80+20)
End If
End If
Dim nm1 As String =
Names1(i1)
lbl11 =
e.Form.CreateControl(nm1, ControlTypeEnum.Button)
lbl11.Text = nm1 '按钮标题:文字内容
lbl11.name = nm1 '按钮名:文字内容
lbl11.Width = 90 '自定义控件宽度
lbl11.Height = 30 '自定义控件高度
lbl11.Left = s1 + 12 '调整控件水平位置:横向间距
lbl11.Top = t1 + 12 '调整控件垂直位置:纵向间距
lbl11.ForeColor = Color.Salmon
'
lbl11.TextAlign = ContentAlignment.BottomCenter '控件文字位置
'
lbl11.CheckAlign = ContentAlignment.TopCenter '控件复选框位置
''
lbl11.BackColor = color.LightSteelBlue
'
lbl11.theme = "system"
e.Form.AddControl(lbl11)
For Each dr As DataRow In
DataTables("分类表").DataRows
lbl11.ToolTip = dr("编号") &
vbcrlf & "名称:" & dr("产品名称")
Next
e.Form.Controls("TabControl1").Tabpages("全部0").AddControl(lbl11)
'将txt加入窗口.控件页面集合"TabControl1"第一个页面Tabpages(0)内
Next
End If
If pg.Text =
"经典类1" Then
Dim lbl11 As
WinForm.Button
Dim Value1 As String =
DataTables("分类表").GetComboListString("产品名称", "[产品分类] = '经典类1'And [日期] =
#" & s & "#", "排序号") '排序:排序号 Desc
Dim sps1() As Char = {"|"}
Dim Names1() As String =
Value1.Split(sps1)
Dim s1 As Integer = 10 '与左边距离
Dim t1 As Integer = 10 '与上边距离
For i1 As Integer = 0 To
Names1.length - 1
If i1
<> 0 Then
If i1 Mod 3 = 0 Then '如果1行显示3个控件
s1 = 10
t1 = t1 + 45 '调整控件纵向间距(30*15)
Else
s1 = s1 + 105 ''调整控件横向间距(80+20)
End If
End If
Dim nm1 As String = Names1(i1)
lbl11 =
e.Form.CreateControl(nm1, ControlTypeEnum.Button)
lbl11.Text = nm1 '按钮标题:文字内容
lbl11.name = nm1 '按钮名:文字内容
lbl11.Width = 90 '自定义控件宽度
lbl11.Height = 30 '自定义控件高度
lbl11.Left = s1 + 12 '调整控件水平位置:横向间距
lbl11.Top = t1 + 12 '调整控件垂直位置:纵向间距
lbl11.ForeColor = Color.Salmon
'
lbl11.TextAlign = ContentAlignment.BottomCenter '控件文字位置
'
lbl11.CheckAlign = ContentAlignment.TopCenter '控件复选框位置
''
lbl11.BackColor = color.LightSteelBlue
'
lbl11.theme = "system"
e.Form.AddControl(lbl11)
For Each dr As DataRow In
DataTables("分类表").DataRows
lbl11.ToolTip = dr("编号") & vbcrlf
& "名称:" & dr("产品名称")
Next
e.Form.Controls("TabControl1").Tabpages("经典类1").AddControl(lbl11)
'将txt加入窗口.控件页面集合"TabControl1"第一个页面Tabpages(0)内
Next
End If
If pg.Text =
"现代类2" Then
Dim lbl11 As WinForm.Button
Dim Value1 As String =
DataTables("分类表").GetComboListString("产品名称", "[产品分类] = '现代类2'And [日期] =
#" & s & "#", "排序号") '排序:排序号 Desc
Dim sps1() As Char = {"|"}
Dim Names1() As String =
Value1.Split(sps1)
Dim s1 As Integer = 10 '与左边距离
Dim t1 As Integer = 10 '与上边距离
For i1 As Integer = 0 To
Names1.length - 1
If i1
<> 0 Then
If i1 Mod 3 = 0 Then '如果1行显示3个控件
s1 = 10
t1 = t1 + 45 '调整控件纵向间距(30*15)
Else
s1 = s1 + 105 ''调整控件横向间距(80+20)
End If
End If
Dim nm1 As String =
Names1(i1)
lbl11 =
e.Form.CreateControl(nm1, ControlTypeEnum.Button)
lbl11.Text = nm1 '按钮标题:文字内容
lbl11.name = nm1 '按钮名:文字内容
lbl11.Width = 90 '自定义控件宽度
lbl11.Height = 30 '自定义控件高度
lbl11.Left = s1 + 12 '调整控件水平位置:横向间距
lbl11.Top = t1 + 12 '调整控件垂直位置:纵向间距
lbl11.ForeColor = Color.Salmon
'
lbl11.TextAlign = ContentAlignment.BottomCenter '控件文字位置
'
lbl11.CheckAlign = ContentAlignment.TopCenter '控件复选框位置
''
lbl11.BackColor = color.LightSteelBlue
'
lbl11.theme = "system"
e.Form.AddControl(lbl11)
For Each dr As DataRow In
DataTables("分类表").DataRows
lbl11.ToolTip = dr("编号") &
vbcrlf & "名称:" & dr("产品名称")
Next
e.Form.Controls("TabControl1").Tabpages("现代类2").AddControl(lbl11)
'将txt加入窗口.控件页面集合"TabControl1"第一个页面Tabpages(0)内
Next
End If
If pg.Text =
"简约类3" Then
Dim lbl11 As
WinForm.Button
Dim Value1 As String =
DataTables("分类表").GetComboListString("产品名称", "[产品分类] = '简约类3'And [日期] =
#" & s & "#", "排序号") '排序:排序号 Desc
Dim sps1() As Char = {"|"}
Dim Names1() As String =
Value1.Split(sps1)
Dim s1 As Integer = 10 '与左边距离
Dim t1 As Integer = 10 '与上边距离
For i1 As Integer = 0 To
Names1.length - 1
If i1
<> 0 Then
If i1 Mod 3 = 0 Then '如果1行显示3个控件
s1 = 10
t1 = t1 + 45 '调整控件纵向间距(30*15)
Else
s1 = s1 + 105 ''调整控件横向间距(80+20)
End If
End If
Dim nm1 As String =
Names1(i1)
lbl11 =
e.Form.CreateControl(nm1, ControlTypeEnum.Button)
lbl11.Text = nm1 '按钮标题:文字内容
lbl11.name = nm1 '按钮名:文字内容
lbl11.Width = 90 '自定义控件宽度
lbl11.Height = 30 '自定义控件高度
lbl11.Left = s1 + 12 '调整控件水平位置:横向间距
lbl11.Top = t1 + 12 '调整控件垂直位置:纵向间距
lbl11.ForeColor = Color.Salmon
'
lbl11.TextAlign = ContentAlignment.BottomCenter '控件文字位置
' lbl11.CheckAlign =
ContentAlignment.TopCenter '控件复选框位置
''
lbl11.BackColor = color.LightSteelBlue
'
lbl11.theme = "system"
e.Form.AddControl(lbl11)
For Each dr As DataRow In
DataTables("分类表").DataRows
lbl11.ToolTip = dr("编号") &
vbcrlf & "名称:" & dr("产品名称")
Next
e.Form.Controls("TabControl1").Tabpages("简约类3").AddControl(lbl11)
'将txt加入窗口.控件页面集合"TabControl1"第一个页面Tabpages(0)内
Next
End If
Next
e.Form.ResumeRedraw()'重新绘制窗口
这个代码,是一个新的写法,与楼上不同,直接在窗口加一个页面集合,确定位置,然后将代码加上去,我感觉代码重复较多,能不能优化一下