Home > Software engineering >  Every TEXT _GotFocus () event is returning to his own name
Every TEXT _GotFocus () event is returning to his own name

Time:09-16

Every TEXT _GotFocus returned to his own () event name


Suppose I 80 text (array controls, the name for the system default)

Dim mm
Private Sub Text1_GotFocus ()
Mm=Mid (Text1. Name, 5, 2)
End Sub

Private Sub Text2_GotFocus ()
Mm=Mid (Text2. Name, 5, 2)
End Sub
,,,
To write 80 GOTFOCUS events

Is there a simple code, I finally take the text as long as the back of the digital (default) so the Name used system

CodePudding user response:

Use control array is not just to solve problems

Too interface design instead of trouble, if you really want to continue to heap garbage enough, in addition to open a small program, loop 80 times, generate the code,

CodePudding user response:

The system default name, why not use an array? Easy and convenient

CodePudding user response:

reference 1/f, crispy big ice cream reply:
control array may be used to solve problems

Too interface design instead of trouble, if you really want to continue to heap garbage enough, in addition to open a small program, loop 80 times, generate the code,

Can also use a small program to modify the Form Form controls.

CodePudding user response:

reference milaoshu1020 reply: 3/f
Quote: reference 1/f, crispy big ice cream reply:

Use control array is not just to solve problems

Too interface design instead of trouble, if you really want to continue to heap garbage enough, in addition to open a small program, loop 80 times, generate the code,

Can also use a small program to modify the Form Form controls.


Change of FRM file is not not line, and they were afraid he see FRM feel more trouble,

CodePudding user response:

The best method is to use the control array and the Index directly read the value of the line
If you don't need to control array is also possible to add a timer control, the Interval attribute is set to 500
Dim mm
Private Sub Timer1_Timer ()
Dim CTL As Control
The Set of CTL=Screen. ActiveControl
If CTL. The Name Like "Text * 'Then' here is to determine whether the Text controls
Mm=Mid (CTL) Name, 5, 2)
End the If
End Sub
So you can add code ~ without each Text control

CodePudding user response:

Also can use in the Form_Load cycle load text (I), set the text (I). The left, the text (I). The top attribute.
Put a set name to txtTest textbox form, the index of 0;
Both dim mm
 

Sub form_load ()
Dim as integer I
For I=1 to 80
The load txtTest (I)
TxtTest. Left=(calculated offset x)
TxtTest. Top=(calculated offset y)
TxtTest. Visible=true
Next
End sub

Sub txtTest_GotFocus (index as an integer)
Mm=index
End sub

CodePudding user response:

Drop off a few (I), correct as follows:
Both dim mm
 

Sub form_load ()
Dim as integer I
For I=1 to 80
The load txtTest (I)
TxtTest (I). Left=(calculating the offset x)
TxtTest (I). Top=(calculated offset y)
TxtTest (I). The visible=true
Next
End sub

Sub txtTest_GotFocus (index as an integer)
Mm=index
End sub
  • Related