Results 1 to 5 of 5

Thread: Highlighting Controls

  1. #1

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Highlighting Controls

    Here is something I wrote for a friend of mine and I figured I would share it. This code snippet will highlight most controls when they receive the focus. It can be further customized. See attached image.

    Here is the code:

    VB Code:
    1. Option Explicit
    2. 'In a Module
    3.  
    4. Public Sub GotFocusFunct(ByVal NameObj As Object, _
    5.                          ByVal lngIndex As Long, _
    6.                          ByVal ShapeObj As Shape)
    7. On Error GoTo ErrHandler
    8.     With NameObj.Item(lngIndex)
    9.         ShapeObj.Move .Left - 50, .Top - 50, _
    10.                     .Width + 100, .Height + 100
    11.         .BackColor = vbYellow
    12.         .SelStart = 0
    13.         .SelLength = Len(.Text)
    14.         ShapeObj.Visible = True
    15.     End With
    16. Exit Sub
    17.  
    18. ErrHandler:
    19.     If Err.Number = 438 Then
    20.         Resume Next 'Handles error when trying to
    21.                     'select the text or change BackColor
    22.                     'of a control that doesn't have that
    23.                     'property
    24.     Else
    25.         MsgBox Err.Number & " - " & Err.Description & " in Module1"
    26.     End If
    27. End Sub
    28.  
    29. Public Sub LostFocusFunct(ByVal NameObj As Object, _
    30.                           ByVal lngIndex As Long, _
    31.                           ByVal ShapeObj As Shape)
    32.     With NameObj.Item(lngIndex)
    33.         ShapeObj.Visible = False
    34.         .BackColor = vbWhite
    35.     End With
    36. End Sub

    and then you put the following code in the GotFocus and LostFocus Events:

    VB Code:
    1. Option Explicit
    2. 'On the Form
    3.  
    4. Private Sub Text1_GotFocus(Index As Integer)
    5.     Call GotFocusFunct(Text1, Index, Shape1)
    6. End Sub
    7.  
    8. Private Sub Text1_LostFocus(Index As Integer)
    9.     Call LostFocusFunct(Text1, Index, Shape1)
    10. End Sub

    Note each control that you use this code with has to have a value entered into it Index property in order for this code to work. It works great with Control Arrays. Additionally, you must add a Shape1 rectangle object to the form.
    Attached Images Attached Images  
    Last edited by Mark Gambo; Sep 13th, 2005 at 06:50 PM.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  2. #2
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Highlighting Controls

    i forgot to say it, but it looks like a real nice piece of code!

  3. #3

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Highlighting Controls

    Thanks for your comments
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  4. #4
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Highlighting Controls

    just as a nice idea:
    VB Code:
    1. Public Sub GotFocusFunct(ByVal NameObj As Object, _
    2.                          ByVal lngIndex As Long, _
    3.                          ByVal ShapeObj As Shape, _
    4.                         [B] ByVal ObjColor as Long[/B])
    5. On Error GoTo ErrHandler
    6.     With NameObj.Item(lngIndex)
    7.         ShapeObj.Move .Left - 50, .Top - 50, _
    8.                     .Width + 100, .Height + 100
    9.         [B].BackColor = ObjColor[/B]
    10.         .SelStart = 0
    11.         .SelLength = Len(.Text)
    12.         ShapeObj.Visible = True
    13.     End With
    14. Exit Sub

    just for added flexibility...i know its easy but

  5. #5

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Highlighting Controls

    Yeah this code can be expanded to do almost anything. Nice code BTW.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


Posting Permissions

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



Click Here to Expand Forum to Full Width