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
Solved

Cut-off the flicker!!

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

809 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