麻烦调用形式2的方法,从一个按钮,点击表格1,vb.net [英] trouble calling a method in form 2 from a button click on form 1, vb.net
问题描述
我有用于创建时间表的程序,当保存的时间表是通过点击表1的一个按钮加载的数据负载,形成2,然后调用形式2的方法来打印数据,形成3。问题是,通话结束后 Form2.Print()
没有对表格2没有数据,如果我打开它,但该数据印刷,形成3。如果我删除仍然工作在 Form2.Print()
中的数据被加载在表2,然后我就可以点击打印按钮,如果我再次打开表2的数据仍然在文本框中。注:理想情况下,我只想发送数据,形成2和表3从表1的打开按钮点击事件,但打印()
上表2的方法做许多事情该程序不仅仅是印刷使它更容易只需要调用复制它在打开的点击它,而不是其他。预先感谢您的帮助。干杯!
表1 code
私人小组Open_Click(BYVAL发件人为System.Object的,BYVALË作为System.EventArgs)把手Open.Click
昏暗的xmlDoc中,作为的XmlDocument
昏暗节点列表作为的XmlNodeList
昏暗的节点的XmlNode
昏暗objForm2为对象=窗体2
xmlDoc中=新的XmlDocument()
xmldoc.Load(C:\ time.xml)
节点列表= xmldoc.SelectNodes(/时间表/作业1)
对于每个节点在节点列表
昏暗的CustName = node.ChildNodes.Item(0).InnerText
Form2.txtbxCustName.Text =的CustName
昏暗WO = node.ChildNodes.Item(1).InnerText
Form2.txtbxWONum.Text = WO
下一个
objForm2.Print()
结束小组
`
表2 code
私人小组btnPrint_Click(BYVAL发件人为System.Object的,BYVALË作为System.EventArgs)把手btnPrint.Click
打印()
结束小组
公用Sub打印()
Form3.labelCustName.text = txtbxCustName.text
Form3.labelWOnum.text = txtbxWOnum.text
Me.Close()
结束小组
没有必要投窗体2
对象,然后调用打印。从表单的新情况下,你会直接。而你每次调用它assining新值文本框内的每个块。
实现你愿意,你可以做很多的方式,而不是 texbox
的对象,我会用字符串
的对象表现出什么。
在你的窗体2和Form3类添加
公共财产XMLDATA作为字符串'使用自己的类或其他类型的列表控件(文本框,)任何你想要的。
你需要做的里面打开的点击
昏暗窗口2为新的窗体2()
如果你想初始化窗口2并form3只有一次,并用它翻过程序,那么你应该从加入这一行至prevent它的设置在关闭()
私人小组Form2_FormClosing(发送者为对象,E作为System.Windows.Forms.FormClosingEventArgs)处理Me.FormClosing
Me.Hide()
e.Cancel = TRUE
结束小组
form2.xmldata = yourxmldata
form2.print()
form2.show()显示窗口2
还是让我现在如果它帮助你。如果没有,我会重新编辑我的答案好让你明白
I have a program for creating a time sheet and when a saved time sheet is loaded by clicking a button on form 1 the data loads to form 2 and then calls a method in form 2 to print the data to form 3. The problem is after the call Form2.Print()
there is no data on form 2 if i open it but still works in that the data is printed to form 3. If I remove Form2.Print()
the data is loaded on form 2 and i can then click the Print button and if i open form 2 again the data is still in the text boxes. NOTE: Ideally I would just send the data to form 2 and form 3 from the Open button click event on form 1 but the Print()
method on form 2 does many things to the program other than just printing making it easier to just call it instead of replicating it in the Open click. Thank You in advance for the help. Cheers!
Form 1 Code
Private Sub Open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Open.Click
Dim xmldoc As XmlDocument
Dim nodelist As XmlNodeList
Dim node As XmlNode
Dim objForm2 As Object = Form2
xmldoc = New XmlDocument()
xmldoc.Load("C:\time.xml")
nodelist = xmldoc.SelectNodes("/Timesheet/Job1")
For Each node In nodelist
Dim CustName = node.ChildNodes.Item(0).InnerText
Form2.txtbxCustName.Text = CustName
Dim WO = node.ChildNodes.Item(1).InnerText
Form2.txtbxWONum.Text = WO
Next
objForm2.Print()
End Sub
`
Form 2 Code
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Print()
End Sub
Public Sub Print()
Form3.labelCustName.text = txtbxCustName.text
Form3.labelWOnum.text = txtbxWOnum.text
Me.Close()
End Sub
No need to cast Form2
to object then call print . from new instance of your form you will directly call it .And you every time assining new values to text box inside for each block .
to achieve what you want you can do many ways Instead of texbox
objects I will show with String
object.
in your Form2 and Form3 class add
Public Property xmldata as String 'use your own class or other types List controls(textbox,.)whatever you want .
'You have to do inside open click
Dim form2 as new Form2()
If you want initialize form2 and form3 only once and use it accross program then you should add this line to prevent it from disposing when closing()
Private Sub Form2_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Me.Hide()
e.Cancel = True
End Sub
form2.xmldata=yourxmldata
form2.print()
form2.show()'show form2
lemme now if it helped you . if not i will reedit my answer so that u understand
这篇关于麻烦调用形式2的方法,从一个按钮,点击表格1,vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!