16,720
社区成员
发帖
与我相关
我的任务
分享Public Class OpSet
Private startBox, stopBox As New TextBox, changeButton As New Button, Rectangle1, Rectangle2 As New Rectangle
Private graphicsFun As Graphics, BrushColor As New SolidBrush(Color.Blue)
Sub New(ByVal frm As Form, ByVal x As Integer, ByVal y As Integer)
startBox.Location = New Point(x, y)
stopBox.Location = New Point(x + startBox.Size.Width + 50, y)
changeButton.Location = New Point(stopBox.Location.X + stopBox.Size.Width + 50, y)
changeButton.Text = "confirm"
graphicsFun = frm.CreateGraphics
graphicsFun.FillRectangle(BrushColor, x, changeButton.Location.Y + changeButton.Width + 50, 200, 10)
AddHandler changeButton.Click, AddressOf changeButton_Click
frm.Controls.AddRange({startBox, stopBox, changeButton})
End Sub
Private Sub changeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim startNum, stopNum As Integer
If (Not Integer.TryParse(startBox.Text, startNum)) OrElse startNum < 0 OrElse startNum > 100 Then
MessageBox.Show("Invalid start value")
Exit Sub
End If
If (Not Integer.TryParse(stopBox.Text, stopNum)) OrElse stopNum < 0 OrElse stopNum > 100 Then
MessageBox.Show("Invalid stop value")
Exit Sub
End If
MessageBox.Show("New values are: start = " & startNum.ToString & ", stop = " & stopNum.ToString)
End Sub
End Class
以下是我主画面的内容,在屏幕上添加了两组上面的类
Public Class Form1
Private opsets As New List(Of OpSet)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
opsets.Add(New OpSet(Me, 100, 300))
opsets.Add(New OpSet(Me, 100, 400))
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End
End Sub
End Class