Solved

Cut-off the flicker!!

Posted on 1999-01-20
2
359 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

911 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

24 Experts available now in Live!

Get 1:1 Help Now