Solved

Move a TImage without flickers

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

762 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