473,396 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to change the color of a button when clicked?

Hi I am new to the forum. I have created a form in Word 2007. I have implemented a radio button on the form. I want to add custom code so that every time the button is clicked, the color of the button changes. For example, I was thinking along the lines of a code that is similar to a snippet that I found on the web:

Expand|Select|Wrap|Line Numbers
  1. Private Sub OptionButton1_Click()
  2. Option Explicit
  3. Dim index As Integer
  4. Dim indicator(5) As ColorConstants
  5.  
  6. Private Sub Form_Load()
  7.   indicator(0) = vbGreen
  8.   indicator(1) = vbRed
  9.   indicator(2) = vbBlack
  10.   indicator(3) = vbYellow
  11.   indicator(4) = vbBlue
  12.  
  13. End Sub
Can you please provde guidance for me?
Thank you.
Vickie
Mar 2 '11 #1
4 8232
Guido Geurs
767 Expert 512MB
This is changing the color each time the optionbutton is clicked.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Dim indicator(5) As Variant
  3. Dim index As Integer
  4.  
  5.  
  6. Private Sub UserForm_Activate()
  7. indicator(0) = vbGreen
  8. indicator(1) = vbRed
  9. indicator(2) = vbBlack
  10. indicator(3) = vbYellow
  11. indicator(4) = vbBlue
  12. index = 0
  13. End Sub
  14.  
  15. Private Sub OptionButton1_Click()
  16.    OptionButton1.BackColor = indicator(index)
  17.    index = index + 1
  18.    If index > 5 Then index = 0
  19. End Sub
Mar 3 '11 #2
imavp2
7
Hi Guido.
Sorry for the delay. Thanks a million for the code and of course it worked. However, once I launched the form I realized it was not what I had in mind. I apologize. I have a form with several radio buttons. I was able to get the background to change colors for each button. I actually wanted the circle itself to change colors. Should I upload the form so you can better visualize what I am trying to accomplish? If you work with me on the code for this once, I am sure that I will catch on and not need to keep coming back. I have some VB6 code for circles that I can also share with you. Let me know if I need to upload both for your review.
Vickie
Mar 11 '11 #3
imavp2
7
Sorry. Ok I will remember to use tags for when uploading code.
Vickie
Mar 11 '11 #4
Guido Geurs
767 Expert 512MB
Please can you attach your code in Bytes?
You want to change the color of the button (the circle)it self?
Than it will not work with the standard radio buttons in VB6.
If so, we will have to create or own buttons!
Mar 11 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jay | last post by:
I have a form used to submit data (no surprises there!). I'd like to be able to populate the same form with previously submitted data. The data lives in a database once submitted and using ASP I...
2
by: NishSF | last post by:
Would anyone have any suggestions/javascript code so that if one clicks the Radio Button "Yes" below he has the option of selecting any of the six CheckBox below. If the user clicks on Radio Button...
1
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and...
1
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
10
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
5
by: swatidesai0407 | last post by:
hi im validating radio buttons i create dis radio button in php based on some how many records of my query. i wrote a javascript to validate this buttons. wat i do is dat wen no radio button...
5
by: Fran Jakers | last post by:
Hello all, I'm new to all this and I could really use some help. I've searched the web but cannot find an answer. I have an HTML form with 3 radio buttons and a search field that calls a...
3
by: jahphill | last post by:
Hey. I thought id make a seperate discusion because the other became a bit lengthy and confusing. Aim: Create a php file which works with the script below, which makes the radiobuttons work =D...
3
johny10151981
by: johny10151981 | last post by:
Hi, Here a code part that create a group box and radio button hGroup=CreateWindowEx(0,L"BUTTON",L"Choose Connection type",...
7
Fary4u
by: Fary4u | last post by:
how can i change radio button into image but functionality should be like radio button ? .pic { background:url(pic.jpg) no-repeat; } <input type=radio src=pic.jpg value=1 name=1> or <input...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.