Solved

Move a TImage without flickers

Posted on 1997-04-14
3
349 Views
Last Modified: 2010-04-06
I hav this piece of code to move a TImage around a form.Of course it is not free of flickers because I change only the Left Top propierties of my TImage in the OnMouseMove Event.
This is my code:
This is my piece of code that I use to move a TImage.Of course,ther are flickers because I use only a change of the Top-Left propierties:
pp is boolean and dragstartx and dragstarty longint.
procedure TForm1.Image1MouseDown(Sender: TObject; Button:TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
inileft:=(sender as timage).left; {Original values}
initop:=(sender as timage).top;
if  button=mbleft then  begin
pp:=true;
DragStartX := X;
DragStartY := Y;
end;
end;

procedure TForm1.Image10MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
 var
  DeltaX : Integer;
 DeltaY : Integer;
begin
if pp=true then
 with (sender as timage) do begin
   DeltaX := X - DragStartX;
   DeltaY := Y - DragStartY;
   Left := Left + DeltaX ;
   Top := Top + DeltaY ;
 end;
end;

procedure TForm1.Image10MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
  var deltax,deltay:integer;
begin
pp:=false;
{end draging}
end;
How can I do to eliminate the flickers?
0
Comment
Question by:cobian
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
sperling earned 80 total points
ID: 1335381
Set
  Image1.ControlStyle := Image1.ControlStyle + [csOpaque]
after creating the image.


Use
  SetBounds (Left+DeltaX, Top+DeltaY, Width, Height)
instead of setting Left and Top


Regards,

Erik.

0
 

Author Comment

by:cobian
ID: 1335382
Sorry,it don't helped.There are horrible flickers all the time?Somebody told me that I can use the API BitBln for that,but HOW?
0
 
LVL 3

Expert Comment

by:sperling
ID: 1335383

Create a large TPaintBox, which covers the area in which you wan't the user to be able to move the image.

Create a bitmap with the same size. This one shouldn't be visible.

Draw the wanted image on the correct position on the bitmaps canvas.

In PaintBox.OnPaint, copy the bitmap to PaintBox1.Canvas using

BitBlt
  (PaintBox.Canvas.Handle, 0, 0,
  PaintBox.Canvas.Width, PaintBox.Canvas.Height,
  Bitmap.Canvas.Handle,
  0, 0,
  SRCCOPY);

When the user moves the image, redraw the bitmap, and call PaintBox.Invalidate. This will force the Paintbox to repaint as soon as possible. You'll wan't to set PaintBox.ControlStyle := PaintBox.ControlStyle + [csOpaque]

If you need source code examples on the implementation of this, you'll need to increase the points a bit... But, the technique I've described is not very difficult to write, so I suggest you give it a try.


Regards,

Erik.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 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