我制作了一个子动画文字框和按钮。
但我的问题如下:
我需要让按钮在相应的文本框中添加/删除1个单元
最后3个潜艇是我的问题
请求回复。
Public Class Form1
Dim IMG(9) As PictureBox
Dim lastIMG = 10
Dim leftorg = 10
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Qntorg = 115
Dim LeftQnt = 115
Dim TopQnt = 125
Dim Rmvorg = 115
Dim LeftRmv = 115
Dim TopRmv = 145
Dim Addorg = 135
Dim LeftAdd = 135
Dim TopAdd = 145
For i = 0 To 9
'Quantidade
Dim tb_qt As New TextBox
With tb_qt
.Size = New Size(40, 20)
.Top = TopQnt
.Left = LeftQnt
LeftQnt = .Left + .Width + 180
.Text = "0"
If .Left + .Width >= Me.Width Then
TopQnt = .Top + 100 + 100
.Top = TopQnt
.Left = Qntorg
LeftQnt = Qntorg
End If
End With
Me.Controls.Add(tb_qt)
'ADD
Dim btn_add As New Button
With btn_add
.Size = New Size(20, 20)
.Top = TopAdd
.Left = LeftAdd
LeftAdd = .Left + .Width + 200
.Text = "+"
If .Left + .Width >= Me.Width Then
TopAdd = .Top + 100 + 100
.Top = TopAdd
.Left = Addorg
LeftAdd = Addorg
End If
End With
Me.Controls.Add(btn_add)
'RMV
Dim btn_rmv As New Button
With btn_rmv
.Size = New Size(20, 20)
.Top = TopRmv
.Left = LeftRmv
LeftRmv = .Left + .Width + 200
.Text = "-"
If .Left + .Width >= Me.Width Then
TopRmv = .Top + 100 + 100
.Top = TopRmv
.Left = Rmvorg
LeftRmv = Rmvorg
End If
End With
Me.Controls.Add(btn_rmv)
AddHandler btn_add.Click, AddressOf btn_add_Click
AddHandler btn_rmv.Click, AddressOf btn_rmv_Click
AddHandler tb_qt.TextChanged, AddressOf tb_qt_TextChanged
Next
End Sub
Public Sub tb_qt_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
'Dim tb_qt As TextBox = DirectCast(sender, TextBox)
'tb_qt.Text = c
End Sub
Public Sub btn_add_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'Dim btn_add As Button = sender
'c = c + 1
'tb_qt_TextChanged(sender, e)
End Sub
Public Sub btn_rmv_Click(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
结束课
答案 0 :(得分:1)
您需要在 def doSomething():Unit = {
aFutureThing().onComplete {
case Success(s) => println("Success: "+s)
case Failure(x) =>
// Take some (hopefully) corrective action here, call for help, etc.
Thread.sleep(1000) // pause a bit
doSomething() // and try again...
}
}
doit()
和相应的Button
之间建立关系。有很多方法可以做到。一种选择是将TextBox
分配给TextBox
的{{1}}属性,例如
Tag
然后,您可以访问Button
的{{1}}事件处理程序中的btn_add.Tag = tb_qt
,并根据需要对其进行操作,例如
TextBox
答案 1 :(得分:0)
从概念上讲,我正在做一个单项,但也会在for / next中工作。
Public Sub Demo(ByVal sender As Control)
Dim cmdDoSomething As New Button With
{
.Name = "cmdDoit",
.Parent = sender,
.Text = "Hello"
}
AddHandler cmdDoSomething.Click, Sub(s As Object, e As EventArgs)
Dim b As Button = CType(s, Button)
MessageBox.Show(b.Text)
End Sub
sender.Controls.Add(cmdDoSomething)
End Sub
或更传统的
Public Sub Demo(ByVal sender As Control)
Dim cmdDoSomething As New Button With
{
.Name = "cmdDoit",
.Parent = sender,
.Text = "Hello"
}
AddHandler cmdDoSomething.Click, AddressOf cmdTryToReturn_Click
sender.Controls.Add(cmdDoSomething)
End Sub
Private Sub cmdTryToReturn_Click(sender As Object, e As EventArgs)
MessageBox.Show(CType(sender, Button).Text)
End Sub
希望这是你正在寻找的,如果没有引导你朝正确的方向发展。
还有一件事,如果您需要将按钮与文本框关联,请考虑将其添加到新创建的按钮的tag属性中。