Solved

Cut-off the flicker!!

Posted on 1999-01-20
2
363 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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 …
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…

730 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