AllExperts > Experts 
Search      

VB.NET

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More VB.NET Answers
Question Library

Ask a question about VB.NET
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Brandon Drake
Expertise
I can answer questions regarding the Graphics object, file access, general optimization, printing (on paper), user controls, program mathematics, the registry, creating macros, processes, and fundamental or basic questions. I have made a few asp.net pages but I do not know the language extensively. I have not done much work with databases but I have created my own database systems.

Experience
I have been programming with visual basic for 6 years. In all I have written programs in about 8 programming languages, although, I only know about 3 well. I have written a few applications but mainly I like to write programs for fun.

 
   

You are here:  Experts > Computing/Technology > Basic > VB.NET > Multiple visual changes to form in one sub

Topic: VB.NET



Expert: Brandon Drake
Date: 7/22/2006
Subject: Multiple visual changes to form in one sub

Question
Ok that explains what I'm seeing. Thank you. If I could ask you one more question then on delays. Apparently I am misunderstanding the use of the timer. How can I add a pause between color changes?
-------------------------

Followup To

Question -
Hey Brandon,

I'm trying to change the background color of an image box repeatedly by just clicking one button.
The problem I'm running into is nothing will change until the sub ends and the only color that shows up is the last color that was assigned to the box background.

I've run the script line by line and it isn't my timer between color changes that is giving me problems. Simply nothing happens to the form until the sub ends.

Do I need to do something between color changes to force an update to the form or is it something else entirely that I'm missing?

Here is an example of what I'm trying to do:

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       PictureBox1.BackColor = Color.Chocolate
       PictureBox2.BackColor = Color.Azure
       PictureBox3.BackColor = Color.Gainsboro

       Timer1.Start()

       PictureBox1.BackColor = Color.AntiqueWhite
       PictureBox2.BackColor = Color.Gold
       PictureBox3.BackColor = Color.Tan

   End Sub


Answer -
Naimah,

First, when a Sub executes, it executes line by line, as fast as the processor can do it--The background color IS changing but it is so fast that you can't see it and the last color is the only color you see because it is the last change made to the picture box.

If you execute the Sub line by line using the debugger, you will not see the changes though.  Visual changes do not normally show up when using the debugger.

What you need to do is detect which color the picture box currently is and then determine which color to make it--So if you determine the color is Chocolate, change the color to Azure and if you determine the color is Gold, change it to Tan.



Good Luck,

Brandon Drake

Answer
Naimah,

There is no easy way to pause while IN a sub.  The Timer control is used to run a piece of code every x seconds where x is a number you specify.

When you use Timer1.Start() you are telling the timer to "Turn on" and start executing a piece of code every x seconds.

The Timer Tick() event is the piece of code that executes.  If you double click the timer control it should take you to it's Tick() event.  The code that you put inside the tick event is the code that will execute every x seconds.



Good Luck,

Brandon Drake

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.