Solved

Floating image over panels

Posted on 2013-11-24
16
478 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to fill array with TArray.Create? 14 79
Newbie Thread Programming 1 139
Best Firemonkey component pack 1 86
Downloading email attachments 2 67
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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 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

19 Experts available now in Live!

Get 1:1 Help Now