以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 动态生成的问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=103785) |
-- 作者:rjh4078 -- 发布时间:2017/7/17 9:22:00 -- 动态生成的问题 dim s as string s="1,2,3,4,5" If s<>"" Then Dim Multi As String = s Dim Values() As String Values = Multi.split(",") f.Controls("pan2").basecontrol.controls.clear Dim ay As Integer = 10 Dim i As Integer = 0 Dim x As Integer = 10 Dim y As Integer = 20 For Index As Integer = 0 To Values.Length - 1 Dim btn = f.CreateControl("bt" & Values(Index), ControlTypeEnum.button) btn.Text =Index+1 & "." & Values(Index) btn.Left = x + i*120 btn.width=Values(Index).length*25 btn.Top = y If Index>0 Then Dim btn1 = f.CreateControl("bt1" & Values(Index), ControlTypeEnum.button) btn1.Left = x + i*120+btn.width btn1.width=75 btn1.Top = y f.Controls("pan2").AddControl(btn1) End If i = i+1 If i Mod 7 = 0 Then i = 0 x = 10 y += 25 End If f.Controls("pan2").AddControl(btn) Next Else f.Controls("pan2").basecontrol.controls.clear End If 上面这个代码是想根据S的内容生成一个动态的按钮组,当S内的顺序大于1时 在2个按钮之间插入一个链接按钮 写到这个地方卡住了 想实现如下图所示的效果 |
-- 作者:有点甜 -- 发布时间:2017/7/17 9:34:00 -- Dim s As String Dim f As WinForm.Form=e.Form s="1,2,3,4,5,6,7,8,9" If s<>"" Then Dim Multi As String = s Dim Values() As String Values = Multi.split(",") f.Controls("pan2").basecontrol.controls.clear Dim ay As Integer = 10 Dim i As Integer = 0 Dim x As Integer = 10 Dim y As Integer = 20 For Index As Integer = 0 To Values.Length - 1 Dim btn = f.CreateControl("bt" & Values(Index), ControlTypeEnum.button) btn.Text =Index+1 & "." & Values(Index) btn.Left = x btn.width=Values(Index).length*25 btn.Top = y x += btn.width f.Controls("pan2").AddControl(btn) If Index<Values.Length - 1 Then Dim btn1 = f.CreateControl("bt1" & Values(Index), ControlTypeEnum.button) btn1.Left = x btn1.width=75 btn1.Top = y f.Controls("pan2").AddControl(btn1) x += btn1.width End If i = i+1 If i Mod 7 = 0 Then i = 0 x = 10 y += 25 End If Next Else f.Controls("pan2").basecontrol.controls.clear End If |
-- 作者:rjh4078 -- 发布时间:2017/7/17 9:49:00 -- 甜老师 大概是这个意思 但是细节有点不妥 比如s=1,2 应该显示12和12之间的按钮 12345时 显示12345和他们直接的按钮 只有1时 只显示1 最后一位数的后面那个按钮也不显示 需要改哪个? |
-- 作者:有点甜 -- 发布时间:2017/7/17 11:32:00 -- 代码没问题啊,就是你需要的啊。 |