Solved

Move a TImage without flickers

Posted on 1997-04-14
3
358 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
[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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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