The evil Windows taskbar is hiding part of one designed tool window (I don't wanna it to be Always on Top).
How to get ClientHeight of Screen easily????
I designed a template dialog, RadioGroupDialog
, with a tool window with only a TRadioGroup
on it, with Form->AutoSize = true
. It is called through its Execute()
method.
On Execute()
, one has to pass a TStringList
with items to put on the TRadioGroup
, the caption of dialog form and the TRect
with Screen absolute coordinates of component where the dialog form will be centered in (i.e., Place->Left = CallingForm->Left + Component->Left
etc.)
Inside the code of Execute()
, after performing some type of autosize to allocate all elements of the TStringList
in TRadioGroup
and after centering the dialog form in expected position, the code tries to maintain dialog position inside Screen.
It is all ok with up, left and right borders, but, because of Windows taskbar, the dialog is covered by it :(
If I can discover ClientHeight of screen, it will be easy to avoid that issue using it instead of Screen->Height
... Also knowing taskbar height would help. Well, I know that that taskbar would be on top, on left and on right of Screen too, so using ClientHeight and ClientWidth would be the best solution..
//---------------------------------------------------------------------------
int __fastcall TRadioGroupDialog::Execute(TStringList *Str, AnsiString DlgCaption, TRect Place)
{
ModalResult = 0;
Caption = DlgCaption;
RadioGroup1->Items->Clear();
RadioGroup1->Items->AddStrings(Str);
int TheHeight = 30*RadioGroup1->Items->Count;
int MaxHeight = 4*Screen->Height/5;
int MinHeight = 30;
if(TheHeight > MaxHeight)
{
TheHeight = MaxHeight;
}
else if(TheHeight < MinHeight)
{
TheHeight = MinHeight;
}
RadioGroup1->Height = TheHeight;
Left = ((Place.Left + Place.Right)/2) - Width / 2;
Top = ((Place.Top + Place.Bottom)/2) - Height / 2;
if(Left + Width > Screen->Width)
{
Left = Screen->Width - Width;
}
if(Top + Height > Screen->Height)
{
Top = Screen->Height - Height;
}
if(Left < 0)
{
Left = 0;
}
if(Top < 0)
{
Top = 0;
}
RadioGroup1->ItemIndex = -1;
return ShowModal();
}
//---------------------------------------------------------------------------
Example: Form1 contains Button1, and when it is pressed it shows the RadioGroupDialog
with four items centered in Button1 with "Olá" of dialog caption:
Form on screen center:
Form on screen center after Button1 is pressed:
Form on bottom of screen:
Form on bottom of screen after Button1 is pressed (see that 4th item is not shown):
Use the Screen->WorkArea...
(Left/Top/Width/Height/Rect) properties to get the coordinates and dimensions of the screen's working area, which is not obscured by the taskbar and other toolbars.