Issue

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????

Detailed description

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->Leftetc.)

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..

The code of Execute()

//---------------------------------------------------------------------------
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();
}
//---------------------------------------------------------------------------

The ugly thing that Windows taskbar does

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: 1

  • Form on screen center after Button1 is pressed: 2

  • Form on bottom of screen: 3

  • Form on bottom of screen after Button1 is pressed (see that 4th item is not shown): 4

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top