toggle l button color in

Posted on 2007-07-21
Last Modified: 2013-11-26
toggle button color to green .
I woulls like to click the button, then its property  color turns green.
Then when it is green, I would like to populate textbox1 with "GO'
I click the button again it goes back to normal color then change the value to stop on textbox1
Question by:zachvaldez
    LVL 38

    Assisted Solution

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If Button1.BackColor <> Color.LightGreen Then
                Button1.BackColor = Color.LightGreen
                TextBox1.Text = "Go"
                Button1.BackColor = System.Windows.Forms.Control.DefaultBackColor
                TextBox1.Text = "Stop"
            End If

        End Sub

    Author Comment

    IN vb6  also?
    LVL 38

    Accepted Solution

    In VB6, first you must set the Style of the button to Graphical in the designer.  Then use this code:

    Private Sub Command1_Click()
        If Command1.BackColor <> RGB(0, 255, 0) Then
            Command1.BackColor = RGB(0, 255, 0)
            Text1.Text = "Go"
            Command1.BackColor = vbButtonFace
            Text1.Text = "Stop"
        End If
    End Sub

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now