首先在窗体上添加Button1,ListBox1,下面是完整代码
创新互联专注为客户提供全方位的互联网综合服务,包含不限于网站制作、成都做网站、巴楚网络推广、微信平台小程序开发、巴楚网络营销、巴楚企业策划、巴楚品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联为所有大学生创业者提供巴楚建站搭建服务,24小时服务热线:18980820575,官方网址:www.cdcxhl.com
Public Class Form1
Public Sub BubbleSort(ByVal arr() As Integer) '冒泡法排序
Dim temp As Double
Dim i, j As Integer
For i = 0 To arr.GetUpperBound(0) - 1
For j = i + 1 To arr.GetUpperBound(0) - 1
If arr(i) arr(j) Then
temp = arr(j)
arr(j) = arr(i)
arr(i) = temp
End If
Next
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '调用
Dim arr() As Integer = {55, 22, 33, 11, 77, 88}
BubbleSort(arr) '调用排序过程
Me.ListBox1.Items.Clear()
For i = 0 To arr.GetUpperBound(0) - 1 '显示排序后结果
Me.ListBox1.Items.Add(arr(i).ToString)
Next
End Sub
End Class
Public Class Form2
Dim test As String
Public Sub New(ByVal _test As String)
test = _test
End Sub
End Class
Form1 中 New Form2("abc") 即可传参给 Form2 中的 test。
但在 VB.NET 中,没必要这么麻烦,只需要声明为 Public,即可直接方法,如:
Public Class Form2
Public test As String
End Class
Form1 中直接 Form2.test = "abc" 即可。
既然子窗体都有同名函数,就应该对子窗体进行一层封装,子类实现不同方法
Public MustInherit Class AbstractChild
Public MustOverride Sub Method1()
End Class
Public Class ChildClass1
Inherits AbstractChild
Public Overrides Sub Method1()
MessageBox.Show("class1")
End Sub
End Class
Public Class ChildClass2
Inherits AbstractChild
Public Overrides Sub Method1()
MessageBox.Show("class2")
End Sub
End Class
Public Class ChildClass3
Inherits AbstractChild
Public Overrides Sub Method1()
MessageBox.Show("class3")
End Sub
End Class
Dim child1 As New ChildClass1()
Dim child2 As New ChildClass2()
Dim child3 As New ChildClass3()
child1.Method1()
child2.Method1()
child3.Method1()