以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]窗口中动态增加按钮并给其添加代码 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=68129) |
||||
-- 作者:moxuejiahui -- 发布时间:2015/5/10 21:39:00 -- [求助]窗口中动态增加按钮并给其添加代码 我点N次某些按钮后会动态生成了一些代码,要想使这些代码运行要怎么设置呢?比尔给某按钮加上代码,或者让生成的代码直接运行要怎么用啊 |
||||
-- 作者:大红袍 -- 发布时间:2015/5/10 21:44:00 -- 动态编译一下 http://www.foxtable.com/help/topics/1487.htm
|
||||
-- 作者:程兴刚 -- 发布时间:2015/5/10 21:45:00 -- 没明白您什么意思,如果是动态添加控件的话,这么办: 1、事先在窗口的全局事件写代码,其代码首先判断控件名称并执行; 2、动态添加控件时指定其名称为全局代码中说判断的控件名称对应即可。 |
||||
-- 作者:moxuejiahui -- 发布时间:2015/5/10 21:46:00 -- 我把代码动态生成在textbox中的,要怎么去运行这些代码呢 |
||||
-- 作者:大红袍 -- 发布时间:2015/5/10 21:46:00 -- 看2楼。 |
||||
-- 作者:moxuejiahui -- 发布时间:2015/5/10 21:56:00 -- 可是代码是后期生成的,会分很多步完成,并且完全不能确定过程,所以全局时间中也没法预先写代码,支能生成在textbox中,然后要怎么去运行这代码呢 其中一按钮多次选择不同容器后点击执行以下代码 Dim mc As WinForm.TextBox = e.Form.Controls("TextBox9") Dim mcs As String = mc.text For Each c As WinForm.Control In e.Form.Controls(""& mcs &"").children e.Form.removeControl(c.name) Next DataTables("临时").DeleteFor("[批次] = \'"& mcs &"\'") Dim bl As Double = 1220 / 345 Dim chang As WinForm.TextBox = e.Form.Controls("TextBox1") Dim kuan As WinForm.TextBox = e.Form.Controls("TextBox2") Dim hd As WinForm.TextBox = e.Form.Controls("TextBox3") Dim sd As WinForm.TextBox = e.Form.Controls("TextBox4") Dim sc As WinForm.TextBox = e.Form.Controls("TextBox6") Dim hc As WinForm.TextBox = e.Form.Controls("TextBox7") Dim jk As WinForm.TextBox = e.Form.Controls("TextBox8") Dim cf As WinForm.ComboBox = e.Form.Controls("ComboBox2") Dim zybb As WinForm.TextBox = e.Form.Controls("TextBox13") Dim x As Integer = jk.text If cf.text = "横裁" Then Dim i As Integer Dim y As Integer Dim nr As String Dim jw As WinForm.TextBox = e.Form.Controls("TextBox14") Dim nr3 As String For y = 1 To sd.text For i = 1 To hd.text Dim x1 As Double = chang.text / bl Dim x2 As Double = kuan.text / bl Dim wzx As Double = (x + (i - 1) * (kuan.text + x)) / bl Dim wzy As Double = (x + (y - 1) * (chang.text + x)) / bl Dim xy As Integer = (y - 1) * hd.text + i Dim mcs1 As String = mcs & xy Dim Panel1 As WinForm.Panel Panel1 = e.Form.CreateControl(""& mcs1 &"", ControlTypeEnum.Panel) Panel1.SetBounds(wzx, wzy, x2, x1) e.Form.Controls(""& mcs &"").AddControl(Panel1) e.Form.Controls(""& mcs1 &"").BackColor = Color.Orangered Dim lbl As WinForm.Label lbl = e.Form.CreateControl(""& mcs1 &"", ControlTypeEnum.Label) Dim gg1 As String = chang.text & "*" & kuan.text lbl.Text = gg1 lbl.Left = x2 / 2 - 30 lbl.Top = x1 / 2 - 15 e.Form.Controls(""& mcs1 &"").AddControl(lbl) nr = "" & vbcrlf & "Dim rt"& mcs1 &" As New prt.RenderText" & vbcrlf & "Dim gg"& mcs1 &" As String = "" "& chang.text &"*"& kuan.text &" "" " & vbcrlf & " rt"& mcs1 &".Text = gg"& mcs1 &" "& vbcrlf &" rt"& mcs1 &".Width = "& kuan.text &" / 10" & vbcrlf & "rt"& mcs1 &".Height = "& chang.text &" / 10" & vbcrlf & "rt"& mcs1 &".Style.Borders.All = New prt.Linedef(0.5, Color.Red) " & vbcrlf & "rt"& mcs1 &".Style.TextAlignHorz = prt.AlignHorzEnum.Center" & vbcrlf & " rt"& mcs1 &".Style.TextAlignVert = prt.AlignVertEnum.Center" & vbcrlf & "rt"& mcs1 &".X = 0.4 + ("& i &" - 1) * ("& kuan.text &" + 4) / 10" & vbcrlf & "rt"& mcs1 &".y = 0.4 + ("& y &" - 1) * ("& chang.text &" + 4) / 10" & vbcrlf & "ra"& mcs &".Children.Add(rt"& mcs1 &")" & vbcrlf & "" zybb.text = zybb.text & nr Next Dim sy As Double = hc.text - hd.text * kuan.text - (hd.text + 1) * x Dim xsy As Double = (x + (hd.text * (kuan.text + x))) / bl Dim ysy As Double = (x + (y - 1) * (chang.text + x)) / bl Dim x3 As Single Dim x4 As Single x3 = sy / bl x4 = chang.text / bl Dim xy1 As Single = hd.text * sd.text + y Dim mcs2 As String = mcs & xy1 Dim Panel2 As WinForm.Panel Panel2 = e.Form.CreateControl(""& mcs2 &"", ControlTypeEnum.Panel) Panel2.SetBounds(xsy, ysy, x3, x4) e.Form.Controls(""& mcs &"").AddControl(Panel2) e.Form.Controls(""& mcs2 &"").BackColor = Color.Orange nr = "" & vbcrlf & "Dim ra"& mcs2 &" As New prt.RenderArea" & vbcrlf & "ra"& mcs2 &".Width = "& sy &" / 10" & vbcrlf & "ra"& mcs2 &".Height = "& chang.text &" / 10" & vbcrlf & "ra"& mcs2 &".X = "& hd.text &" * ("& kuan.text &" + "& x &") / 10" & vbcrlf & "ra"& mcs2 &".y = ("& y &" - 1) * ("& chang.text &" + "& x &") / 10" & vbcrlf & "" zybb.text = zybb.text & nr nr3 = ""& vbcrlf & "ra"& mcs &".Children.Add(ra"& mcs2 &")" jw.text = jw.text & nr3 Next Dim sy2 As Double = sc.text - sd.text * chang.text - (sd.text + 1) * x Dim xsy2 As Double = x / bl Dim ysy2 As Double = (x + sd.text * (chang.text + x)) / bl Dim x5 As Single Dim x6 As Single x5 = hc.text / bl x6 = sy2 / bl Dim xy2 As Single = hd.text * sd.text + sd.text + 1 Dim mcs3 As String = mcs & xy2 Dim Panel3 As WinForm.Panel Panel3 = e.Form.CreateControl(""& mcs3 &"", ControlTypeEnum.Panel) Panel3.SetBounds(xsy2, ysy2, x5, x6) e.Form.Controls(""& mcs &"").AddControl(Panel3) e.Form.Controls(""& mcs3 &"").BackColor = Color.Orange nr = "" & vbcrlf & "Dim ra"& mcs3 &" As New prt.RenderArea" & vbcrlf & "ra"& mcs3 &".Width = "& hc.text &" / 10" & vbcrlf & "ra"& mcs3 &".Height = "& sy2 &" / 10 " & vbcrlf & " ra"& mcs3 &".X = 0 " & vbcrlf & "ra"& mcs3 &".y = "& sd.text &" * ("& chang.text &" + "& x &") / 10" & vbcrlf & "" zybb.text = zybb.text & nr nr3 = ""& vbcrlf & "ra"& mcs &".Children.Add(ra"& mcs3 &")" jw.text = jw.text & nr3 End If 会生成代码的主体部分 另一按钮会生成以下代码以确定专业报表的设置完成并预览 Dim kt As String = "" & vbcrlf & "Dim doc As New PrintDoc" & vbcrlf & "Dim ra板材 As New prt.RenderArea" & vbcrlf & "ra板材.Width = 122.6" & vbcrlf & "ra板材.Height = 245" & vbcrlf & "ra板材.x = 14.9" & vbcrlf & "ra板材.y = 24.8" & vbcrlf & "ra板材.Style.Borders.All = New prt.Linedef(0.3, Color.Red) " & vbcrlf & "" Dim zybb As WinForm.TextBox = e.Form.Controls("TextBox13") Dim jw As WinForm.TextBox = e.Form.Controls("TextBox14") Dim nr2 As String = "" & vbcrlf & " Doc.Body.ChildRen.Add(ra板材) " & vbcrlf & "doc.Preview()" zybb.text = kt & zybb.text & jw.text & nr2 jw.text = "" 希望大家能帮我看看,谢谢 红色部分为专业报表的设置代码
[此贴子已经被作者于2015/5/10 21:57:06编辑过]
|
||||
-- 作者:大红袍 -- 发布时间:2015/5/10 22:03:00 -- 看2楼啊 |
||||
-- 作者:moxuejiahui -- 发布时间:2015/5/10 22:26:00 -- 我看了二楼,也设了,可是生成的报表始终保持第一种,不知道怎么回事,红袍要不要下载下来试试看啊,两个代码 Dim Code As String Code = zybb.text & vbcrlf Functions.Add("打印",Code) Functions.Complie() zybb.text = "" 全局变量 Select Case e.Sender.Name Case "打印" Functions.Execute("打印") End Select 别切提示已添加相同键的项, 要不帮我写下怎么运行zybb.text中代码的代码吧红袍兄
|
||||
-- 作者:大红袍 -- 发布时间:2015/5/10 22:30:00 -- 如下代码
Functions.remove("打印") |
||||
-- 作者:moxuejiahui -- 发布时间:2015/5/10 22:30:00 -- 忘记说了,窗口中在第二页签里面有一分区面板第二页,先点预裁,后点生成,专业报表就设置完成了 |