Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Move a TImage without flickers

Posted on 1997-04-14
3
Medium Priority
?
371 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 160 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

661 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