【发布时间】:2013-05-21 15:46:04
【问题描述】:
问题
邪恶的 Windows 任务栏隐藏了一个设计工具窗口的一部分(我不希望它始终位于顶部)。
如何轻松获取屏幕的ClientHeight???
详细说明
我设计了一个模板对话框,RadioGroupDialog,带有一个工具窗口,上面只有一个TRadioGroup,还有Form->AutoSize = true。它通过其Execute() 方法调用。
在Execute() 上,必须传递一个TStringList,其中包含要放在TRadioGroup 上的项目、对话框表单的标题和TRect,以及对话框表单将居中的组件的屏幕绝对坐标(即Place->Left = CallingForm->Left + Component->Left等)
在Execute() 的代码中,在执行某种类型的自动调整大小以分配TRadioGroup 中TStringList 的所有元素并将对话框表单居中于预期位置之后,代码尝试保持对话框在屏幕内的位置。
上下左右边框都可以,但是,由于Windows任务栏,对话框被它覆盖了:(
如果我能发现屏幕的 ClientHeight,使用它而不是 Screen->Height 将很容易避免该问题...也知道任务栏高度会有所帮助。好吧,我知道任务栏也会在 Screen 的顶部、左侧和右侧,因此使用 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 项未显示):
【问题讨论】:
标签: screen c++builder taskbar