Solved

Move a TImage without flickers

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now