Board index » delphi » "Smart Moving" dailog help needed

"Smart Moving" dailog help needed

I'm writing a Help dialog. The control needs to be able to know how to
move itself out of the way of the form below it when it's pointing to
a TWinControl on another form (e.g. the dialog is really just a TForm
with style fsStayOnTop) the user can click on a help rect. that will
give some info and take them to the control on the active form below
it. This part works fine already... I just need to tell the dialog
"Hey, you're blocking the view... move" to an intelligent location.

Does anyone know how I can figure out where this is and move the form
intelligently?

Thanks for any help!

Bill Artemik
Programmer / Analyst
Droste Consultants, Inc.
b...@droste1.com

"The TWO rules for success in life are:

     1. NEVER tell them everything you know."

 

Re:"Smart Moving" dailog help needed


Quote
"Bill Artemik" <b...@droste1.com> wrote in message

news:395e127d.67750900@news4.newscene.com...

Quote
> I'm writing a Help dialog. The control needs to be able to know how to
> move itself out of the way of the form below it when it's pointing to
> a TWinControl on another form (e.g. the dialog is really just a TForm
> with style fsStayOnTop) the user can click on a help rect. that will
> give some info and take them to the control on the active form below
> it. This part works fine already... I just need to tell the dialog
> "Hey, you're blocking the view... move" to an intelligent location.

> Does anyone know how I can figure out where this is and move the form
> intelligently?

All controls have a ClientToScreen method that given a coordinate relative
to the control will return one relative to the screen. Using

aPoint := targetControl.ClientToScreen (Point (0, 0));

and

SystemParametersInfo (SPI_GetWorkArea, 0, @WorkAreaRect, 0);

In conjunction with targetControl Width &Height, and the help forms Top,
Left, Width, and Height you should be able to figure out the best placement
for the help form. To position the form just use its SetBounds method.

Re:"Smart Moving" dailog help needed


The following function places a form next (above, below, left, right) to
another form:

procedure MoveForm(Form1, Form2: TCustomForm; Align: TAlign);
var
  R1, R2: TRect;
begin
  R1 := Form1.BoundsRect;
  SystemParametersInfo(SPI_GETWORKAREA, 0, @R2, 0) then
  case Align of
    alTop: Form2.BoundsRect := Rect(R1.Left, R2.Top, R1.Right, R1.Top);
    alBottom: Form2.BoundsRect := Rect(R1.Left, R1.Top, R1.Right,
R1.Bottom);
    alLeft: Form2.BoundsRect := Rect(R2.Left, R1.Bottom, R1.Left,
R2.Bottom);
    alRight: Form2.BoundsRect := Rect(R1.Right, R1.Top, R2.Right,
R1.Bottom);
  end;
end;

"Bill Artemik" <b...@droste1.com> schreef in bericht
news:395e127d.67750900@news4.newscene.com...

Quote
> I'm writing a Help dialog. The control needs to be able to know how to
> move itself out of the way of the form below it when it's pointing to
> a TWinControl on another form (e.g. the dialog is really just a TForm
> with style fsStayOnTop) the user can click on a help rect. that will
> give some info and take them to the control on the active form below
> it. This part works fine already... I just need to tell the dialog
> "Hey, you're blocking the view... move" to an intelligent location.

> Does anyone know how I can figure out where this is and move the form
> intelligently?

> Thanks for any help!

> Bill Artemik
> Programmer / Analyst
> Droste Consultants, Inc.
> b...@droste1.com

> "The TWO rules for success in life are:

>      1. NEVER tell them everything you know."

Re:"Smart Moving" dailog help needed


That works!

Thanks to both of you for the solutions! That works!

Bill

On Wed, 28 Jun 2000 17:24:16 +0200, "M.H. Avegaart"

Quote
<avega...@NOSPAMmccomm.nl> wrote:
>The following function places a form next (above, below, left, right) to
>another form:

>procedure MoveForm(Form1, Form2: TCustomForm; Align: TAlign);
>var
>  R1, R2: TRect;
>begin
>  R1 := Form1.BoundsRect;
>  SystemParametersInfo(SPI_GETWORKAREA, 0, @R2, 0) then
>  case Align of
>    alTop: Form2.BoundsRect := Rect(R1.Left, R2.Top, R1.Right, R1.Top);
>    alBottom: Form2.BoundsRect := Rect(R1.Left, R1.Top, R1.Right,
>R1.Bottom);
>    alLeft: Form2.BoundsRect := Rect(R2.Left, R1.Bottom, R1.Left,
>R2.Bottom);
>    alRight: Form2.BoundsRect := Rect(R1.Right, R1.Top, R2.Right,
>R1.Bottom);
>  end;
>end;

>"Bill Artemik" <b...@droste1.com> schreef in bericht
>news:395e127d.67750900@news4.newscene.com...
>> I'm writing a Help dialog. The control needs to be able to know how to
>> move itself out of the way of the form below it when it's pointing to
>> a TWinControl on another form (e.g. the dialog is really just a TForm
>> with style fsStayOnTop) the user can click on a help rect. that will
>> give some info and take them to the control on the active form below
>> it. This part works fine already... I just need to tell the dialog
>> "Hey, you're blocking the view... move" to an intelligent location.

>> Does anyone know how I can figure out where this is and move the form
>> intelligently?

>> Thanks for any help!

>> Bill Artemik
>> Programmer / Analyst
>> Droste Consultants, Inc.
>> b...@droste1.com

>> "The TWO rules for success in life are:

>>      1. NEVER tell them everything you know."

Bill Artemik
Programmer / Analyst
Droste Consultants, Inc.
b...@droste1.com

"The TWO rules for success in life are:

     1. NEVER tell them everything you know."

Re:"Smart Moving" dailog help needed


Quote
"Bill Artemik" <b...@droste1.com> wrote in message

news:395e127d.67750900@news4.newscene.com...

Quote
> I'm writing a Help dialog. The control needs to be able to know how to
> move itself out of the way of the form below it when it's pointing to
> a TWinControl on another form (e.g. the dialog is really just a TForm
> with style fsStayOnTop) the user can click on a help rect. that will
> give some info and take them to the control on the active form below
> it. This part works fine already... I just need to tell the dialog
> "Hey, you're blocking the view... move" to an intelligent location.

> Does anyone know how I can figure out where this is and move the form
> intelligently?

You can check the screen coordinates of the TWinControl and move the help
dialog so that it does not hide the TWinControl.  To get the screen
coordinates of the TWinControl use TWinControl.ClientToScreen:

var scrnpt, pt : TPoint;

pt.x := 0;
pt.y := 0;
scrnpt := TWinControl(the control you want visible).ClientToScreen(pt);

Christo Crause

Re:"Smart Moving" dailog help needed


Spoke too soon...

I can now get the coordinates of the control on the main form but is
there an easier way to figure out if my top form is covering the
control? I'm getting confused with the math on this...

I tried to see if the Point.x IN [elf.Left .. (Self.Left +
Self.Width)]  but that didn't evaluate properly (looks right but
Delphi just blew over it without a blink...)

Any Ideas (or examples) of the math / logic I need here? I don't
remember my set geometry too well... :(

Quote
 <ccra...@ing.sun.ac.za.REMOVE> wrote:
>"Bill Artemik" <b...@droste1.com> wrote in message
>news:395e127d.67750900@news4.newscene.com...
>> I'm writing a Help dialog. The control needs to be able to know how to
>> move itself out of the way of the form below it when it's pointing to
>> a TWinControl on another form (e.g. the dialog is really just a TForm
>> with style fsStayOnTop) the user can click on a help rect. that will
>> give some info and take them to the control on the active form below
>> it. This part works fine already... I just need to tell the dialog
>> "Hey, you're blocking the view... move" to an intelligent location.

>> Does anyone know how I can figure out where this is and move the form
>> intelligently?

>You can check the screen coordinates of the TWinControl and move the help
>dialog so that it does not hide the TWinControl.  To get the screen
>coordinates of the TWinControl use TWinControl.ClientToScreen:

>var scrnpt, pt : TPoint;

>pt.x := 0;
>pt.y := 0;
>scrnpt := TWinControl(the control you want visible).ClientToScreen(pt);

>Christo Crause

Bill Artemik
Programmer / Analyst
Droste Consultants, Inc.
b...@droste1.com

"The TWO rules for success in life are:

     1. NEVER tell them everything you know."

Re:"Smart Moving" dailog help needed


Did you know that Windows already contains TRect calculation functions ?
Look up SetRect, SetRectEmpty, CopyRect, InflateRect, IntersectRect,
UnionRect, SubstractRect, OffsetRect, IsRectEmpty, EqualRect and PtInRect.

In your case:

var
  R: TRect;
begin
  if IntersectRect(R, Form1.BoundsRect, Form2.BoundsRect) then
  begin
    // Form2 covers Form1
  end;
end;

"Bill Artemik" <b...@droste1.com> schreef in bericht
news:395c55cc.84982498@news4.newscene.com...

Quote
> Spoke too soon...

> I can now get the coordinates of the control on the main form but is
> there an easier way to figure out if my top form is covering the
> control? I'm getting confused with the math on this...

> I tried to see if the Point.x IN [elf.Left .. (Self.Left +
> Self.Width)]  but that didn't evaluate properly (looks right but
> Delphi just blew over it without a blink...)

> Any Ideas (or examples) of the math / logic I need here? I don't
> remember my set geometry too well... :(

>  <ccra...@ing.sun.ac.za.REMOVE> wrote:

> >"Bill Artemik" <b...@droste1.com> wrote in message
> >news:395e127d.67750900@news4.newscene.com...
> >> I'm writing a Help dialog. The control needs to be able to know how to
> >> move itself out of the way of the form below it when it's pointing to
> >> a TWinControl on another form (e.g. the dialog is really just a TForm
> >> with style fsStayOnTop) the user can click on a help rect. that will
> >> give some info and take them to the control on the active form below
> >> it. This part works fine already... I just need to tell the dialog
> >> "Hey, you're blocking the view... move" to an intelligent location.

> >> Does anyone know how I can figure out where this is and move the form
> >> intelligently?

> >You can check the screen coordinates of the TWinControl and move the help
> >dialog so that it does not hide the TWinControl.  To get the screen
> >coordinates of the TWinControl use TWinControl.ClientToScreen:

> >var scrnpt, pt : TPoint;

> >pt.x := 0;
> >pt.y := 0;
> >scrnpt := TWinControl(the control you want visible).ClientToScreen(pt);

> >Christo Crause

> Bill Artemik
> Programmer / Analyst
> Droste Consultants, Inc.
> b...@droste1.com

> "The TWO rules for success in life are:

>      1. NEVER tell them everything you know."

Re:"Smart Moving" dailog help needed


No, I didn't know these functions existed! Thanks.

I'm dealing with a component on the form and a StayOnTop form, though.
I'm not trying to move one form beside another. I'm trying to move the
"hovering" form from obscuring a control on the form beneath it so I
have to figure out if the "hovering" form IS obscuring the focused
control and if so, WHERE I can logically move the "hovering" form so
it's still in full view (assuming that's possible, otherwise I do
nothing and let the user move the darn thing...)

Is there a way to convert the TPoint coordinates to a TRect? I know
how to get the Screen Coordinates of the target control on the
"beneath" form (  ClientToScreen ) but this returns a TPoint. Adding
the TPoint1coordinates from ClientToScreen(Point(0,0)) to
TPoint2.X=TPoint1.X + TargetControl.Width; TPoint2.Y := TPoint1.Y +
TargetControl.Height

This gives me the Upper Left and Bottom Right coordinates relative the
the screen (what I need). Using a Windows function that tells me if
these two have a common intersection point would sure be nicer that
what I have come up with so far (works but really NOT pretty! In a
bar, this would be a 4 beer thing... KWIM?).

Thanks for the tips on the IntresectRect and UnionRect (and all the
others I didn't know about)! This puts me back on the right track.

Quote
 <avega...@NOSPAMmccomm.nl> wrote:
>Did you know that Windows already contains TRect calculation functions ?
>Look up SetRect, SetRectEmpty, CopyRect, InflateRect, IntersectRect,
>UnionRect, SubstractRect, OffsetRect, IsRectEmpty, EqualRect and PtInRect.

>In your case:

>var
>  R: TRect;
>begin
>  if IntersectRect(R, Form1.BoundsRect, Form2.BoundsRect) then
>  begin
>    // Form2 covers Form1
>  end;
>end;

>"Bill Artemik" <b...@droste1.com> schreef in bericht
>news:395c55cc.84982498@news4.newscene.com...
>> Spoke too soon...

>> I can now get the coordinates of the control on the main form but is
>> there an easier way to figure out if my top form is covering the
>> control? I'm getting confused with the math on this...

>> I tried to see if the Point.x IN [elf.Left .. (Self.Left +
>> Self.Width)]  but that didn't evaluate properly (looks right but
>> Delphi just blew over it without a blink...)

>> Any Ideas (or examples) of the math / logic I need here? I don't
>> remember my set geometry too well... :(

>>  <ccra...@ing.sun.ac.za.REMOVE> wrote:

>> >"Bill Artemik" <b...@droste1.com> wrote in message
>> >news:395e127d.67750900@news4.newscene.com...
>> >> I'm writing a Help dialog. The control needs to be able to know how to
>> >> move itself out of the way of the form below it when it's pointing to
>> >> a TWinControl on another form (e.g. the dialog is really just a TForm
>> >> with style fsStayOnTop) the user can click on a help rect. that will
>> >> give some info and take them to the control on the active form below
>> >> it. This part works fine already... I just need to tell the dialog
>> >> "Hey, you're blocking the view... move" to an intelligent location.

>> >> Does anyone know how I can figure out where this is and move the form
>> >> intelligently?

>> >You can check the screen coordinates of the TWinControl and move the help
>> >dialog so that it does not hide the TWinControl.  To get the screen
>> >coordinates of the TWinControl use TWinControl.ClientToScreen:

>> >var scrnpt, pt : TPoint;

>> >pt.x := 0;
>> >pt.y := 0;
>> >scrnpt := TWinControl(the control you want visible).ClientToScreen(pt);

>> >Christo Crause

>> Bill Artemik
>> Programmer / Analyst
>> Droste Consultants, Inc.
>> b...@droste1.com

>> "The TWO rules for success in life are:

>>      1. NEVER tell them everything you know."

Bill Artemik
Programmer / Analyst
Droste Consultants, Inc.
b...@droste1.com

"The TWO rules for success in life are:

     1. NEVER tell them everything you know."

Other Threads