vb.net如何让父窗体工具栏的保存对话框在所有子窗体通用
请教:保存子窗体上的成果图或表,就要在某个活动的子窗体上调用父窗体工具栏的保存按钮来打开保存对话框,请问:如何让对话框知道当前是哪个子窗体?或如何获取当前子窗体?...
请教:保存子窗体上的成果图或表,就要在某个活动的子窗体上调用父窗体工具栏的保存按钮来打开保存对话框,请问:如何让对话框知道当前是哪个子窗体?或如何获取当前子窗体?
展开
1个回答
展开全部
'代码中Button控件自行在窗体中添加并改名
***********************************父窗体代码:
Public Class Form1
Public Sub From1_保存Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles From1_保存Button.Click
Select Case sender.name
Case "From1_保存Button"
MsgBox("提交的窗体是From1")
Case "Form2_提交Button"
MsgBox("提交的窗体是From2")
End Select
Form2.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_显示子窗体.Click
Form2.ShowDialog()
End Sub
End Class
***********************************子窗体代码:
Public Class Form2
Private Sub Form2_提交Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Form2_提交Button.Click
Form1.From1_保存Button_Click(Form2_提交Button, New System.EventArgs)
End Sub
End Class
***********************************
方法满多的,起码三四种,比如用一个全局变量保存当前提交窗体名,执行操作的代码读取这个全局变量就行。最方便的应该是做过程
Public Sub DateBaseAdd(ByVal From As Form)
,然后父窗体跟子窗体都能调用这个全局过程,同时传入窗体名称
***********************************父窗体代码:
Public Class Form1
Public Sub From1_保存Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles From1_保存Button.Click
Select Case sender.name
Case "From1_保存Button"
MsgBox("提交的窗体是From1")
Case "Form2_提交Button"
MsgBox("提交的窗体是From2")
End Select
Form2.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_显示子窗体.Click
Form2.ShowDialog()
End Sub
End Class
***********************************子窗体代码:
Public Class Form2
Private Sub Form2_提交Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Form2_提交Button.Click
Form1.From1_保存Button_Click(Form2_提交Button, New System.EventArgs)
End Sub
End Class
***********************************
方法满多的,起码三四种,比如用一个全局变量保存当前提交窗体名,执行操作的代码读取这个全局变量就行。最方便的应该是做过程
Public Sub DateBaseAdd(ByVal From As Form)
,然后父窗体跟子窗体都能调用这个全局过程,同时传入窗体名称
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询