如:txtID(TextBox)
txtDate(TextBox)
txtNum(TextBox)
等
有什麼辦法可以把(TextBox)集合起來
然後用一個KeyUp的事件程序,
代表整個(TextBox)使用這個共同的KeyUp事件程序
PS:不是建立控制項陣列
如:txt(0), txt(1)
PS:而是利用變數或是物件集合起來
如:物件(0) = txtID
物件(1) = txtDate
物件(2) = txtNum
又可以使用事件程序
2006-11-05 05:54:18 · 1 個解答 · 發問者 Anonymous in 電腦與網際網路 ➔ 程式設計
'若用WithEvens的話,WithEvens不支持陣列變數,故要以陣列變數取代可能不行,建議直接寫個副程式比較快,或者可用以下方式'版本VB6.0'以下在模組Const WM_KEYUP = &H101Const WM_SYSKEYUP = &H105 '按ALTDeclare Function CallWindowProc& Lib "user32" Alias "CallWindowProcA" (ByVal F&, ByVal H&, ByVal M&, ByVal W&, ByVal L&)Declare Function GetWindowLong& Lib "user32" Alias "GetWindowLongA" (ByVal H&, ByVal I&)Declare Sub SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal H&, ByVal I&, ByVal N&)Public P&(2), A(2) As TextBoxFunction WP&(ByVal H&, ByVal M&, ByVal W&, ByVal L&) Dim I% For I = 0 To 2 If H = A(I).hWnd Then Exit For Next If M = WM_KEYUP Or M = WM_SYSKEYUP Then '你要執行的程式 Form1.Caption = "KeyCode= " & W End If WP = CallWindowProc(P(I), H, M, W, L)End Function'以下在表單,表單置3個TextBox,Name=txtID,txtDate,txtNum'結束程式時請直接按表單關閉鈕(×),勿按下VB的結束鈕(■)以免VB被關掉Private Sub Form_Load() Dim I% Set A(0) = txtID Set A(1) = txtDate Set A(2) = txtNum For I = 0 To 2 P(I) = GetWindowLong(A(I).hWnd, -4) SetWindowLong A(I).hWnd, -4, AddressOf WP NextEnd SubPrivate Sub Form_Unload(Cancel As Integer) Dim I% For I = 0 To 2 SetWindowLong A(I).hWnd, -4, P(I) Set A(I) = Nothing NextEnd Sub
2006-11-06 11:49:23 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋