问题
邪恶的 Windows 任务栏隐藏了一个设计工具窗口的一部分(我不希望它始终位于顶部)。
如何轻松获取屏幕的ClientHeight????
详细说明
我设计了一个模板对话框,RadioGroupDialog
带有一个工具窗口,上面只有一个TRadioGroup
,带有Form->AutoSize = true
. 它是通过它的Execute()
方法调用的。
在 上Execute()
,必须传递TStringList
带有项目的TRadioGroup
,对话框表单的标题和TRect
对话框表单将居中的组件的屏幕绝对坐标(即Place->Left = CallingForm->Left + Component->Left
等)
在 的代码中Execute()
,在执行某种类型的自动调整大小以分配TStringList
in的所有元素TRadioGroup
并将对话框表单居中于预期位置之后,代码尝试在 Screen 内保持对话框位置。
上下边框都可以,但是,由于 Windows 任务栏,对话框被它覆盖:(
如果我能发现屏幕的 ClientHeight,那么使用它而不是Screen->Height
......也很容易避免这个问题......也知道任务栏的高度会有所帮助。好吧,我知道该任务栏也会在屏幕的顶部、左侧和右侧,因此使用 ClientHeight 和 ClientWidth 将是最好的解决方案..
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();
}
//---------------------------------------------------------------------------
Windows任务栏做的丑事
示例:Form1 包含 Button1,当按下它时,它会显示RadioGroupDialog
以 Button1 为中心的四个项目,对话框标题为“Olá”:
屏幕中心表格:
按下 Button1 后屏幕中心的表单:
屏幕底部的表格:
按下 Button1 后屏幕底部的表单(请参阅第 4 项未显示):