[英]How would I dynamically insert a textbox that has the same values at all times as a different textbox elsewhere on the page in VB.net?
[英]How do i give a value a TextBox create dynamically when i click and doubleClick? vb.net
我有這樣創建的文本框:
Dim Result1 As New TextBox
Result1.ID = "BOX_Result" & a & "_" & i
我想當我在該文本框上單擊以輸入“確定”,並且在單元格中雙擊以輸入NOT / OK時
重要! 如果我嘗試Result.Click不起作用,則動態創建TextBox,得到該錯誤:“ Result1.Click顯示錯誤:” Click不是'System.Web.UI.WebControls.TextBox'的事件”
我嘗試那樣,但不起作用:
AddHandler Result1.Click,我的地址.Result1_Click
Private Sub Result1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
Result1.Text = "OK"
End Sub
我想當一個人單擊動態創建的文本框但不起作用時單擊。 感謝幫助
您可以將以下行添加到TextBox定義中:
Result1.Attributes.Add("onclick", "this.value = 'OK';")
Result1.Attributes.Add("ondblclick", "this.value = 'NOT/OK';")
在此代碼中,當用戶雙擊文本框時,將顯示文本“ NOT / OK”。 在您的問題中,您談論的是雙擊“單元格”。 如果該“單元格”不是TextBox,請說明它是哪種控件。
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim tb As New TextBox 'Create the new TextBox
AddHandler tb.DoubleClick, AddressOf TB_DoubleClick 'Add a handler to the textbox`s DoubleClick event
AddHandler tb.Click, AddressOf TB_Click
'Set any other properties of textbox you want here....
Me.Controls.Add(tb) 'Add the textbox to the forms controls
End Sub
'This is the textbox Click event handler sub
Private Sub TB_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim tb As TextBox = DirectCast(sender, TextBox) 'Cast the (sender) into a textbox to get access to the textbox`s properties
Result1.Text = "OK"
End Sub
'This is the textbox DoubleClick event handler sub
Private Sub TB_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs)
Dim tb As TextBox = DirectCast(sender, TextBox) 'Cast the (sender) into a textbox to get access to the textbox`s properties
Result1.Text = "NOT OK"
End Sub
我為您創建了一個簡單的示例:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Result1 As New TextBox
Result1.Text = "BOX_Result"
Dim loc As New Point With {.Y = 117, .X = 111}
Result1.Location = loc
Me.Controls.Add(Result1)
AddHandler Result1.Click, AddressOf Me.Result1_Click
End Sub
Private Sub Result1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim txt As TextBox = sender
sender.Text = "OK"
End Sub
End Class
希望你想要
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.