Solved

Floating image over panels

Posted on 2013-11-24
16
483 Views
Last Modified: 2013-11-29
Hello guys,

I am trying to find a way to make my image float from one panel to another when I click on the button. But I am having a problem, as you can see in my code, I have a second panel and when the image moves from one panel to another, it goes behind the panels and after finished the moving, the image disappears.

I trying to find a solution in web but I haven't found anything so far, maybe you can help me with this task.

I made the code in Delphi XE4

Thanks
Alex
FloatImage.zip
0
Comment
Question by:hidrau
  • 8
  • 4
  • 4
16 Comments
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39673859
See if do you like this :

procedure TForm1.Button1Click(Sender: TObject);
var
 i : Integer;
begin
  for I := 0 to 10 do
  Begin
      Image7.Top := Image7.Top + 20;
      Sleep(100);
      Application.ProcessMessages;
  End;
  Image7.Top := -117;
  Image7.Parent := nil;
  Image7.Parent := Panel2;
  for I := 0 to 10 do
  Begin
      Image7.Top := Image7.Top + 20;
      Sleep(100);
      Application.ProcessMessages;
  End;
  Image7.Top := 26;
  Image7.Parent := nil;
  Image7.Parent := Panel3;
end;

Open in new window

0
 
LVL 26

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 39673867
Timage is inherited from TGraphicControl which is not have window handle and we cannot set real window z-order. But Panel can be set :-)

Try this - put Timage on TPanel same size as Image and run you code this way:
procedure TForm1.Button1Click(Sender: TObject);
var
 i : Integer;
begin
  for I := 0 to 20 do
  Begin
    Panel4.Top := Panel4.Top + 20;
    Sleep(100);
    Application.ProcessMessages
  End;
end;

Open in new window



I see you old question too. When you do drag and drop of image - you can hide and destroy parent Panel and recreate another on destination or just start dragging Panel too.
0
 
LVL 1

Author Comment

by:hidrau
ID: 39674272
Hello MarqusG, thanks for your helping and trick.

Hello Sinisav, thanks for your post solution.

I wonder if there isn't any component TImage that  inherited from TGraphicControl. Do you know any? I have the TMS components, I don't know if there is any that has that inheritance. I need to check.

I'll take a look at. I'd like to have only the Timage component without another panel behind it. I need to think what it more suitable to me.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 26

Expert Comment

by:Sinisa Vuk
ID: 39674278
maybe this custom component will work:
http://www.rsdn.ru/forum/delphi/1642145.1
0
 
LVL 1

Author Comment

by:hidrau
ID: 39674544
Sinisav,

I took a look at it but I wasn't able to install it in my Delphi,
I am at company right now and here we have only Delphi 2010 and
I don't know how to install this component.

I use Delphi XE4 at home, but I am newbie on it, I am used to work with Delphi 7 that I also have in company.

Do you think that it will work for what I want?
0
 
LVL 1

Author Closing Comment

by:hidrau
ID: 39677955
When you can, please, answer my last question. Thanks
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39678084
Hi hidrau. Just for curiosity: what was wrong with my code? I tested in a project and it moved the panel making it slide down from panel1 to panel3: Did I misunderstood your question?
0
 
LVL 1

Author Comment

by:hidrau
ID: 39678136
Hi MarqusG,

No, you didn't. I just can't do the way you gave me the code, that is not a good solution for what I was trying to do.

Sinisav gave a solution to workaround and and the notion why the image doesn't go over the panel. Please, don't get me wrong when I close the point giving to him the points.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39678202
Absolutely no problem for ponts :) sinisav has helped me too many times and he's one of those skilled experts I told you about in your other question.
Good luck with your game development.
Cheers
0
 
LVL 1

Author Comment

by:hidrau
ID: 39678223
MarqusG, I thank you very much for some helps too. You are also good at delphi. I hope one day to be as good as you and Sinisav.

Well, on the other hand, I hope you can help me ahead.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39678247
Be sure I'll help if I'll can do it :)
0
 
LVL 26

Expert Comment

by:Sinisa Vuk
ID: 39680341
Found component just like you need (TImageWindow on about.com - great article):
http://delphi.about.com/library/bluc/text/uc092700b.htm
(line where IMAGEWINDOW.DCR is you can remove or create this dcr file and add small bmp image with name TIMAGEWINDOW to show it as image in componets tab)
0
 
LVL 1

Author Comment

by:hidrau
ID: 39680372
Hello Sinisav,

Once again, thank you and I will test it on weekend.

What I am doing "  a kind of game " it is totally different that is my work. :)
0
 
LVL 1

Author Comment

by:hidrau
ID: 39684406
Hello Sinisav,

I found a problem when I use TflowPanel, I notice that my Image lost the heigh and left place where it was when its parent was TflowPanel. That doesn't happen with Tpanel.

I tried to work around this, but I didn't have any success.

I wonder if you have any idea how to solve this.

See the example in my file
FloatImage.zip
0
 
LVL 26

Expert Comment

by:Sinisa Vuk
ID: 39684761
You missed one point. When you set parent to some control - control keep left/top position relative to old parent and on new there is a "jump". After you set new parent you must translate relative position to new parent.

old_pt, new_pt, current_pt: TPoint;
new_parent, old_parent: TWincontrol;
...
old_pt := Point(img.Left, img.Top); //current point
old_parent := img.Parent;
new_parent: = Form1;

new_pt := old_pt; //current point
new_pt := old_parent.ClientToScreen(new_pt); //move to screen
new_pt := new_parent.ScreenToClient(new_pt); //back to new parent
img.Parent := new_parent; //move to new parent
img.SetBounds(new_pt.X, new_pt.Y, img.Width, img.Height);

// do move here

//if you want to set new parent back - use same code - but with different parent
old_pt := Point(img.Left, img.Top); //current point
old_parent := img.Parent;
new_parent: = Panel3;

new_pt := old_pt; //current point
new_pt := old_parent.ClientToScreen(new_pt); //move to screen
new_pt := new_parent.ScreenToClient(new_pt); //back to new parent
img.Parent := new_parent; //move to new parent
img.SetBounds(new_pt.X, new_pt.Y, img.Width, img.Height);

Open in new window

0
 
LVL 1

Author Comment

by:hidrau
ID: 39685088
Thanks Sinisav.

I understood now :)
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert Jpg /PNG To GIF 5 137
Intraweb download file link ? 1 134
When i run adoquery my application freezes 26 166
Tidtcpserver listening on multiports? 1 27
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

803 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