Solved

Cut-off the flicker!!

Posted on 1999-01-20
2
358 Views
Last Modified: 2009-07-29
I have image controls on my form and they respond to
mouse clicks by displaying pictures(bitmap).But the
everytime i click on an image the form flickers suggesting
that it reloads.How can i get i stop it from flickering?
Also when i click on the image, another one gets loaded
at the top right cornern of the form.How can i stop this
too ?
A sample code for the click event is as follows:

Private Sub Image1_Click()

     Set Picture = LoadPicture("c:\cross.bmp")
     Set Image1.Picture = LoadPicture("c:\cross.bmp")
    Else
     Set Picture = LoadPicture("c:\nought.bmp")
     Set Image1.Picture = LoadPicture("c:\nought.bmp")
    End If
End Sub
0
Comment
Question by:onalenna
2 Comments
 
LVL 14

Accepted Solution

by:
waty earned 60 total points
ID: 1469566
Use the following code :

SetRedraw frm, false



SetRedraw frm,True

Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long


Public Sub SetRedraw(frm As Form, bRedraw As Boolean)
   ' #VBIDEUtils#************************************************************
   ' * Programmer Name  : Waty Thierry
   ' * Web Site         : www.geocities.com/ResearchTriangle/6311/
   ' * E-Mail           : waty.thierry@usa.net
   ' * Date             : 19/11/98
   ' * Time             : 16:43
   ' * Module Name      : Lib_Module
   ' * Module Filename  : Lib.bas
   ' * Procedure Name   : SetRedraw
   ' * Parameters       :
   ' *                    frm As Form
   ' *                    bRedraw As Boolean
   ' **********************************************************************
   ' * Comments         : Enabled/Disable Window redraw for window flickering
   ' *  This will increase greatly the speed of work
   ' *
   ' **********************************************************************

   If (bRedraw = True) Then
      LockWindowUpdate 0
      frm.Refresh
   Else
      LockWindowUpdate frm.hwnd
   End If

End Sub


0
 
LVL 18

Expert Comment

by:mdougan
ID: 1469567
Here are a couple of ideas to help:

First, the reason you are getting a copy of the image in the upper right coner of your form is the line in your code that says:

 Set Picture = LoadPicture("c:\cross.bmp")

In this case, Picture is going to be the Picture property of the form.  The form will flicker if you change it's picture property, as it has to redraw itself.  If you don't want the picture to show up in the corner of your form, get rid of this line, and the one like it in the Else condition.

Secondly, using LoadPicture is very slow, and may cause flicker.  You should only use it if there are multiple bmps that you want the user to view.  What I do is to put image controls on my form, set their picture property to the bmps at "design time" then I set their visible properties to false.  So, if I created two hidden image controls, one called imgCross with Cross.bmp loaded at design time into the picture property, and another called imgNought with nought.bmp loaded at design time into the picture property, then I would change the code to read something like:

   If (whatever your if condition is)
     Set Image1.Picture = imgCross.Picture
    Else
     Set Image1.Picture = imgNought.Picture
    End If  

This is much faster because you are not loading the bmp from a file each time (which is very slow).  Also, your application is not dependent on an external bmp file (that could get deleted by the  user).  The only downside is that loading bmps into images at design time makes your exe bigger.  But, if these are small icons, then this effect is minimal.

Good Luck,

MD
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 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

20 Experts available now in Live!

Get 1:1 Help Now