I have on my screen 1 line, and this line has 8 text fields. All text fields have a unique name, for example:
address1
, phone1
, comment1
, time1
, timer1
, call1
, person1
, delivery1
I want to make these names to be dynamically names so that I can produce more text field (in button off the first line) automatically by pushing a button. How can I make the names of dynamic objects like names automatically added to the name, for example: address (1), address (2), ... address (x) ..., etc.
The form needs to function and look like an Excel form. I am using Visual Studio 2013 and write code in VB.
Thank you all.
Public Class Form1
Dim TextdCount1 As Integer = 1
Dim TextitCount1 As Integer = 1
Dim d(10) As String
Dim it(10) As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'הקוד של הכפתור
Dim TextdName1 As String = "d" & TextdCount1
Dim TextitName1 As String = TimeOfDay
'משתנה בשם textboxname1
'שווה לטקסט ו מספר שבשמתנה textboxcount1
If TextdCount1 <= 5 Then
CreateNewTextBox(TextdName1, TextdName1, 25, 50, 10, TextdCount1 * 25 + 10)
TextdCount1 += 1
'60 אורך התיבה
'25 + 10 הפרשי הגובהה בין התיבות
CreateNewTextBox(TextitName1, TextitName1, 60, 50, 40, TextitCount1 * 25 + 10)
TextitCount1 += 1
End If
End Sub
Private Sub CreateNewTextBox(ByVal Name As String, ByVal Text As String, ByVal Width As Integer,
ByVal Height As Integer, ByVal Left As Integer, ByVal Top As Integer)
Dim TextBox1 As New TextBox With
{
.Name = Name,
.Text = Text,
.Width = Width,
.Height = Height,
.Left = Left,
.Top = Top
}
Me.Controls.Add(TextBox1)
AddHandler TextBox1.TextChanged, AddressOf TextBox_TextChanged
d(0) = TextBox1.Text
Dim TextBoxit1 As New TextBox With
{
.Name = Name,
.Text = Text,
.Width = Width,
.Height = Height,
.Left = Left,
.Top = Top
}
Me.Controls.Add(TextBoxit1)
AddHandler TextBoxit1.TextChanged, AddressOf TextBox_TextChanged
it(0) = TextBoxit1.Text
End Sub
Private Sub TextBox_TextChanged(sender As Object, e As EventArgs)
Dim TextBox1 As TextBox = DirectCast(sender, TextBox)
d(0) = TextBox1.Text
End Sub
Private Sub TextBoxit1_TextChanged(sender As Object, e As EventArgs)
Dim TextBoxit1 As TextBox = DirectCast(sender, TextBox)
it(0) = TextBoxit1.Text
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
MsgBox("d = " + d(0))
MsgBox("in time = " + it(0))
End Sub
End Class
so now, the 1 text box is d1 (its id and going to be d1, d2, d3 and act) the 2 text box need to save the time, now when save the value off d to d(0) and the value off time to it(0) when i press the button to show the value off d(0) and it(0) its show me just the it(0) 2 time. what i doing Wrong? Thanks for all your help :)
Aucun commentaire:
Enregistrer un commentaire