Vb.net 将文本从一个文本框复制到另一个表单上的文本框,并在文本框之间排序
我还在vb.net上学习,但我有一个主窗体(form1),它有两列。一个叫红色,另一个叫黄色。我有一个按钮可以打开一个表单(form2),它有一个文本框,允许用户输入某人的名字,还有一个组合框来选择颜色。当他们点击form2上的submit按钮时,这个名字会显示在form1的相应列中。form1上的两种颜色都有自己的文本框。红色有文本框1,黄色有文本框2。有人能帮我做这件事吗?我正在使用Visual Studio 2010 VB.Net。谢谢Vb.net 将文本从一个文本框复制到另一个表单上的文本框,并在文本框之间排序,vb.net,textbox,Vb.net,Textbox,我还在vb.net上学习,但我有一个主窗体(form1),它有两列。一个叫红色,另一个叫黄色。我有一个按钮可以打开一个表单(form2),它有一个文本框,允许用户输入某人的名字,还有一个组合框来选择颜色。当他们点击form2上的submit按钮时,这个名字会显示在form1的相应列中。form1上的两种颜色都有自己的文本框。红色有文本框1,黄色有文本框2。有人能帮我做这件事吗?我正在使用Visual Studio 2010 VB.Net。谢谢 Danny从简单的工作流角度来看,您可以让表单2调用
Danny从简单的工作流角度来看,您可以让表单2调用表单1上的方法,并提供新名称和颜色。然后,表单1会将名称添加到正确的列中。有很多方法可以处理这个问题——一种是让表单1实例化表单2,然后为采用名称和颜色的方法传入委托引用 因此,在表格1中—
Public Sub HandleAdd(name as String, color as String)
' Do Stuff Here.
End Sub
Public Sub AddPlayerButton_Click(sender as Object, e as EventArgs) Handles AddPlayerButton.Click
Dim frm As New Form2
frm.AfterAdd = AddressOf HandleAdd
frm.Show
End Sub
并以表格2—
Public Property AfterAdd As Action(of String, String)
Public Sub OKButton_Click(sender as Object, e as EventArgs) Handles OK.Click
If AfterAdd IsNot Nothing Then AfterAdd(playerName.value, playerColor.value)
End Sub
或者类似的东西。有很多方法可以做到这一点……这里有另一种 格式1中的代码:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim f2 As New Form2
If f2.ShowDialog = Windows.Forms.DialogResult.OK Then
Select Case f2.ComboBox1.SelectedItem.ToString.ToLower
Case "red"
TextBox1.AppendText(f2.TextBox1.Text & Environment.NewLine)
Case "yellow"
TextBox2.AppendText(f2.TextBox1.Text & Environment.NewLine)
Case Else
MessageBox.Show("Unkown Color!")
End Select
End If
End Sub
End Class
表格2:
Public Class Form2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.DialogResult = Windows.Forms.DialogResult.Cancel
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If TextBox1.TextLength > 0 AndAlso ComboBox1.SelectedIndex <> -1 Then
Me.DialogResult = Windows.Forms.DialogResult.OK
End If
End Sub
End Class
公共类表单2
私有子按钮1\u单击(发送者作为对象,e作为事件参数)处理按钮1。单击
Me.DialogResult=Windows.Forms.DialogResult.Cancel
端接头
私有子按钮2\u单击(发送者作为对象,e作为事件参数)处理按钮2。单击
如果TextBox1.TextLength>0,并且选择了ComboBox1.dex-1,则
Me.DialogResult=Windows.Forms.DialogResult.OK
如果结束
端接头
末级
textbox1和textbox2多行文本框也是吗?…您只需根据所选颜色将在表格2中输入的名称附加到正确的名称上即可?是的,textbox1和textbox2都是多行的,是的,我希望在表格1上根据在表格2中输入和选择的内容按颜色排序名称