Board index » cppbuilder » Re: (BCB5) Using ClientToScreen() and ScreenToCLient()

Re: (BCB5) Using ClientToScreen() and ScreenToCLient()


2003-12-12 09:19:45 AM
cppbuilder5
"Mike Knoblock" < XXXX@XXXXX.COM >wrote:
Quote
Could some kind person give me an example of how to use
ClientToScreen [...]
TPoint p,s;
p.x = Panel1->Left;
p.y = Panel1->Top;
s = Panel1->ClientToScreen(p);
You can get the screen coordinates of the panel by using it's
parent control's ClientToScreen method. Assuming that Panel1's
parent is Form1:
p.x = Panel1->Left;
p.y = Panel1->Top;
s = this->ClientToScreen( p );
~ JD
 
 

Re:Re: (BCB5) Using ClientToScreen() and ScreenToCLient()

Could some kind person give me an example of how to use ClientToScreen
and/or ScreenToClient to move a form to a location defined by the position
of a control on another form? Specifically, when I right-click on a Panel1
in Form1 I want Form 2 to appear with its bottom-right corner touching
Panel1's top-left corner.
Here is what I tried:
TPoint p,s;
p.x = Panel1->Left;
p.y = Panel1->Top;
s = Panel1->ClientToScreen(p);
s.x -= Form2->Width;
s.y -= Form2->Height;
Form2->Left = s.x;
Form2->Top = s.y
Form2->Show();
This can't be right because Form2 shows up all over the place, sometimes
offscreen.
This is making my head hurt - can anyone straighten me out?
TIA
Mike
 

Re:Re: (BCB5) Using ClientToScreen() and ScreenToCLient()

"Mike Knoblock" < XXXX@XXXXX.COM >wrote in message
Quote
TPoint p,s;
p.x = Panel1->Left;
p.y = Panel1->Top;
s = Panel1->ClientToScreen(p);
Since you are calling ClientToScreen() on the panel itself, you should be
using 0,0 as the coordinates instead:
TPoint p,s;
p.x = 0;
p.y = 0;
s = Panel1->ClientToScreen(p);
Otherwise, to use the client's Left and Top, you should be calling
ClientToScreen() on the Panel's Parent instead:
TPoint p,s;
p.x = Panel1->Left;
p.y = Panel1->Top;
s = Panel1->Parent->ClientToScreen(p);
Or, Form1 is the Panel's Parent:
TPoint p,s;
p.x = Panel1->Left;
p.y = Panel1->Top;
s = this->ClientToScreen(p);
Alternatively, you could just use the Panel's ClientOrigin property, which
already calculates the screen coordinates of the top-left corner for you:
TPoint p = Panel1->ClientOrigin;
Form2->Left = p.x - Form2->Width;
Form2->Top = p.y - Form2->Height;
Gambit
 

{smallsort}

Re:Re: (BCB5) Using ClientToScreen() and ScreenToCLient()

Remy:
Once again: thanks.
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Mike Knoblock" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>TPoint p,s;
>p.x = Panel1->Left;
>p.y = Panel1->Top;
>s = Panel1->ClientToScreen(p);

Since you are calling ClientToScreen() on the panel itself, you should be
using 0,0 as the coordinates instead:

TPoint p,s;
p.x = 0;
p.y = 0;
s = Panel1->ClientToScreen(p);

Otherwise, to use the client's Left and Top, you should be calling
ClientToScreen() on the Panel's Parent instead:

TPoint p,s;
p.x = Panel1->Left;
p.y = Panel1->Top;
s = Panel1->Parent->ClientToScreen(p);

Or, Form1 is the Panel's Parent:

TPoint p,s;
p.x = Panel1->Left;
p.y = Panel1->Top;
s = this->ClientToScreen(p);

Alternatively, you could just use the Panel's ClientOrigin property, which
already calculates the screen coordinates of the top-left corner for you:

TPoint p = Panel1->ClientOrigin;
Form2->Left = p.x - Form2->Width;
Form2->Top = p.y - Form2->Height;


Gambit