| |

VerySource

 Forgot password?
 Register
Search
View: 743|Reply: 3

Can the control be dynamically generated

[Copy link]

2

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-24 16:00:01
| Show all posts |Read mode
I have this idea: enter a number in the text of a form, such as 3. Then in this form, 3 text controls are automatically generated.
I do not know if you have any way.
Thank you.
Reply

Use magic Report

1

Threads

7

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-11 07:15:02
| Show all posts
First put a command space and the index of the text1 control is set to 0.
Private Sub Command1_Click ()
Load Text1 (1)
Text1 (1) .Top = Text1 (0) .Top + 1000
Text1 (1) .Visible = 1
Load Text1 (2)
Text1 (2) .Top = Text1 (1) .Top + 1000
Text1 (2) .Visible = 1
End Sub
Reply

Use magic Report

0

Threads

46

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-2-14 22:15:01
| Show all posts
The way upstairs is also good.

In fact, VB can also generate controls dynamically, but it cannot generate control arrays. If you want to use control arrays, you need to reorganize it yourself.

Option Explicit
Dim WithEvents text1 As VB.TextBox
Dim text2 As VB.TextBox

Private Sub Form_Load ()
  Set text1 = Controls.Add ("VB.TextBox", "text1")
  text1.Visible = True
  
  Set text2 = Controls.Add ("VB.TextBox", "text21")
  text2.Visible = True
  text2.Top = 500
End Sub
Reply

Use magic Report

0

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-2-16 23:15:01
| Show all posts
'Join a TextBox
        Set ctlText = Controls.Add ("VB.TextBox", "ctlText1", Form1)

        'Set the position and size of the TextBox
        ctlText.Move (ctlDynamic.Left + ctlDynamic.Width + 50), _
                        1, 2500, 100
        'Set the background color of the textBox to blue and the foreground color to white
        ctlText.BackColor = vbBlue
        ctlText.ForeColor = vbWhite
        'Make TextBox visible
        ctlText.Visible = True
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list