Solved

Cut-off the flicker!!

Posted on 1999-01-20
2
364 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

705 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