如何让一个表单中的事件在另一个表单中执行。我有一个表格(New Well表格),有2个文本框,一个组合框和一个按钮。只要主窗体上需要新的进度条(Stage Tally Main),就会调用此方法。每当我填写New well的信息并点击按钮时,我想要Stage Tally Main添加一个进度条,其中包含来自文本框和组合框的信息。如何在New Well表单上创建一个按钮,在Stage Tally Main上添加一个进度条?
答案 0 :(得分:0)
请注意,在下面的代码中,菜单项加载的新井表格和向下的是一个名为go_Progess_bar()的公共子表单。代码描述了在某个位置创建进度条,等等等等。基本上我想要以另一种形式在这个表单上执行的所有代码我可以用一个简单的初始化:public sub some_name()
Public Class Form1
Private Sub NewWellToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NewWellToolStripMenuItem.Click
Dim NewWell As New NewWellForm()
NewWell.ShowDialog()
End Sub
Public Sub go_Progress_Bar()
Dim ctrl As Control
Dim i As Integer = 0
For Each ctrl In Controls
If TypeOf ctrl Is ProgressBar Then
i = i + 1
End If
Next
Dim NumProgressBar As String = Convert.ToString(i)
Dim pBar As New ProgressBar()
pBar.Location = New System.Drawing.Point(20, 50 * (2 * i + 1))
pBar.Name = "progressBar" + NumProgressBar
pBar.Width = 1200
pBar.Height = 30
Dim CrewAndWell As New Label
CrewAndWell.Name = CrewSelection + WellSelection
CrewAndWell.Location = New System.Drawing.Point(20, 50 * (2 * i + 1) - 20)
CrewAndWell.Width = 100
CrewAndWell.Height = 20
CrewAndWell.Text = CrewSelection + ": " + WellSelection
Controls.Add(CrewAndWell)
Controls.Add(pBar)
End Sub
下面是新的井表代码,代表form2。忽略按钮单击事件以外的所有其他内容。单击该按钮时,form1.go_Progress_Bar()调用go_Progress_Bar,代码在form1上执行。穴居人可以做到这么简单。
Public Class NewWellForm
Private Sub NewWellForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox1.Items.AddRange(CrewList.ToArray())
End Sub
Private Sub AddWell_Click(sender As Object, e As EventArgs) Handles AddWell.Click
CrewSelection = ComboBox1.SelectedItem
WellSelection = WellNameText.Text
Form1.go_Progress_Bar()
Close()
End Sub
结束班