CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1

    Question Changeing the color of a button in a text field

    in my program there is a section for credit there are fields like amount ,amt paid ,amt owed if the amount owed if greater than 0 i would like for it to turn a button red so it will show if the person owes money thanks for any help

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Changeing the color of a button in a text field

    Set your Button's Style to Graphical, then set it's background color property to red

  3. #3

    Question Re: Changeing the color of a button in a text field

    yes i know that what i was trying to do the button is normaly vb gray if a amount goes into the owed field it will automaticaly change the color to red thanks again for the help

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Changeing the color of a button in a text field

    Now, I'm not with you
    You want to change the button's color, right....
    Now include the code to set the style to graphical and backcolor of the button to red in the txtAmountOwed_Change event.

    Or am I understanding you wrong¿

  5. #5

    Arrow Re: Changeing the color of a button in a text field

    this is the code for the credit text field

    Code:
    Private Sub pcredit_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then
            ccity.SetFocus
     End If
    SaveCurrentRecord
    End Sub
    i know i need to add something like

    if pcredit is > 1 then Command1.BackColor = vbRed


    does this help any

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: Changeing the color of a button in a text field

    Here is a quick sample.

    Code:
    Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
      If KeyCode = 13 Then
        If Val(Text1.Text) > 0 Then Command1.BackColor = RGB(250, 0, 0)
      End If
    End Sub
    Last edited by peejavery; January 12th, 2006 at 12:40 AM.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7

    Exclamation Re: Changeing the color of a button in a text field

    ok thank you this code works

    Code:
    Private Sub pcredit_KeyDown(KeyCode As Integer, Shift As Integer)
      If KeyCode = vbKeyReturn Then
        If Val(pcredit.Text) > 0 Then Command75.BackColor = vbred
        preturn.SetFocus
      End If
    End Sub
    now my question about this is

    my program allows you to enter in several records and has a next and back button to scroll through the records how can i keep the button red and turn it back gray when you go to a record that has a 0 balance in it

  8. #8
    Join Date
    May 2002
    Posts
    10,943

    Re: Changeing the color of a button in a text field

    EDIT: Create a function that is called when onkeypress is triggered on each of the input boxes. Below is an example. You can even use element arrays instead of naming each text input.

    Code:
    Dim tot as integer
    
    Private Sub checktotal()
      tot = Text1.Text
      tot = tot + Text2.Text
      tot = tot + Text3.Text
      tot = tot + Text4.Text
      If tot > 0 Then Command1.BackColor = RGB(250, 0, 0)
    End Sub
    
    Private Sub Text1_KeyPress(KeyAscii As Integer)
      call checktotal()
    End Sub
    Private Sub Text2_KeyPress(KeyAscii As Integer)
      call checktotal()
    End Sub
    Private Sub Text3_KeyPress(KeyAscii As Integer)
      call checktotal()
    End Sub
    Private Sub Text4_KeyPress(KeyAscii As Integer)
      call checktotal()
    End Sub
    Last edited by peejavery; January 13th, 2006 at 12:18 AM.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  9. #9

    Thumbs up Re: Changeing the color of a button in a text field

    i got it to work thanks guys this is the commands i use

    Code:
     
    If Val(ppower.Text) > 0 Then Command10.BackColor = vbBlue Else Command10.BackColor = &H8000000F
    If Val(pcredit.Text) > 0 Then Command11.BackColor = vbBlue Else Command11.BackColor = &H8000000F

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

Featured