+ Reply to Thread
Results 1 to 2 of 2

using class module

  1. #1
    tom taol
    Guest

    using class module



    my userform has a lot of textboxes.
    i want to change backcolor with yellow in is focused a textbox using
    class module.

    *** Sent via Developersdex http://www.developersdex.com ***

  2. #2
    Michel Pierron
    Guest

    Re: using class module

    Hi Tom,
    I do not think that it is possible with a module of class. To do that, a
    timer is needed; a trick of the kind:

    In a standard module:
    Option Explicit
    Private Declare Function SetTimer Lib "user32" _
    (ByVal hwnd As Long, ByVal nIDEvent As Long _
    , ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    Private Declare Function KillTimer Lib "user32" _
    (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
    Private iTimer As Long

    Sub TimerStop(Optional dummy As Byte = 0)
    If iTimer Then KillTimer 0&, iTimer
    iTimer = 0
    End Sub

    Sub TimerStart(iVal&)
    If iTimer Then TimerStop
    iTimer = SetTimer(0&, 0&, ByVal iVal, AddressOf TimerProc)
    End Sub

    Private Sub TimerProc(ByVal lHwnd&, ByVal lMsg&, ByVal lIDEvent&, ByVal
    lTime&)
    On Error GoTo 1
    Dim Ctl As Control
    For Each Ctl In UserForm1.Controls
    If Left$(Ctl.Name, 7) = "TextBox" Then
    If Ctl.Name = UserForm1.ActiveControl.Name Then
    Ctl.BackColor = &HFFFF&
    Else
    Ctl.BackColor = &H80000005
    End If
    End If
    Next Ctl
    Exit Sub
    1: TimerStop
    MsgBox Err.Number & vbLf & Err.Description, 48
    End Sub

    In UserForm module:
    Private Sub UserForm_Initialize()
    Me.TextBox1.SetFocus
    TimerStart 250
    End Sub

    Private Sub UserForm_QueryClose(Cancel%, CloseMode%)
    TimerStop
    End Sub

    Regards,
    MP

    "tom taol" <[email protected]> a écrit dans le message de news:
    %[email protected]...
    >
    >
    > my userform has a lot of textboxes.
    > i want to change backcolor with yellow in is focused a textbox using
    > class module.
    >
    > *** Sent via Developersdex http://www.developersdex.com ***




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1