我想将TCustomForm
个后代显示为对话框,以便它们位于poOwnerFormCenter
。但是FormStyle
fsNormal
FormStyle
fsMDIChild
FormStyle = fsNormal
时,正确定位表单的相同代码无法设置FormStyle = fsMDIChild
为procedure TForm3.Button1Click(Sender: TObject);
var
AModalForm: TForm;
begin
AModalForm := TForm.Create(Self);
try
AModalForm.Position := poOwnerFormCenter;
AModalForm.ShowModal;
finally
AModalForm.Free;
end;
end;
时的正确位置。
当辅助表单有program Project2;
uses
Vcl.Forms,
Unit2 in 'Unit2.pas' {Form2},
Unit3 in 'Unit3.pas' {Form3};
{$R *.res}
var
AMainForm: TForm2;
A: TApplication;
begin
A := Application;
A.Initialize;
A.MainFormOnTaskbar := True;
A.CreateForm(TForm2, AMainForm);
A.Run;
end.
时,Button1打开模态对话框,如下所示:
但是当辅助表单具有unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Menus;
type
TForm2 = class(TForm)
Button1: TButton;
Panel1: TPanel;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
{$R *.dfm}
uses
Unit3;
procedure TForm2.Button1Click(Sender: TObject);
var
AForm: TForm3;
begin
AForm := TForm3.Create(Self);
AForm.FormStyle := fsMDIChild;
end;
procedure TForm2.Button2Click(Sender: TObject);
var
AForm: TForm3;
begin
AForm := TForm3.Create(Self);
AForm.FormStyle := fsNormal;
end;
end.
时,定位似乎与MDI Child对MDI Parent的位置有关,而不是MDI Child的绝对位置:
我不确定是否犯了任何错误,如果这可能是错误或正常行为。
以下代码用于显示对话框:
object Form2: TForm2
Left = 0
Top = 0
Caption = 'Form2'
ClientHeight = 356
ClientWidth = 635
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
FormStyle = fsMDIForm
OldCreateOrder = False
Visible = True
PixelsPerInch = 96
TextHeight = 13
object Panel1: TPanel
Left = 0
Top = 0
Width = 97
Height = 356
Align = alLeft
TabOrder = 0
object Button1: TButton
Left = 8
Top = 39
Width = 75
Height = 25
Caption = 'fsMDIChild'
TabOrder = 0
OnClick = Button1Click
end
object Button2: TButton
Left = 8
Top = 8
Width = 75
Height = 25
Caption = 'fsNormal'
TabOrder = 1
OnClick = Button2Click
end
end
end
DPR
unit Unit3;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm3 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
var
AModalForm: TForm;
begin
AModalForm := TForm.Create(Self);
try
AModalForm.Position := poOwnerFormCenter;
AModalForm.ShowModal;
finally
AModalForm.Free;
end;
end;
end.
PAS
object Form3: TForm3
Left = 0
Top = 0
Caption = 'Form3'
ClientHeight = 336
ClientWidth = 635
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
Visible = True
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 8
Top = 8
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
end
DFM
Vaessen
PAS
Vaessen
DFM
public void findPatientsInFamily(String family) {
System.out.printf("\n\nFinding patients in family %s\n", family);
findPatients(Patient.FAMILY.matches().value(family));
}
public void findPatientsInSystem(String system) {
System.out.printf("\n\nFinding patients in system %s\n", system);
findPatients(Patient.IDENTIFIER.hasSystemWithAnyCode(system));
}
@SuppressWarnings("rawtypes")
public void findPatients(ICriterion criterion) {
try {
Bundle bundle = client.search().forResource(Patient.class).where(criterion).returnBundle(Bundle.class).execute();
for (BundleEntryComponent entry : bundle.getEntry()) {
if (entry.getResource().getResourceType() == ResourceType.Patient) {
Patient patient = (Patient) entry.getResource();
System.out.printf("%s\n", parser.encodeResourceToString(patient));
}
}
}
catch(Exception e) {
System.out.printf("Cannot find patients\n%s\n", e.getMessage());
}
}
答案 0 :(得分:1)
在SO和其他地方尝试了几个想法之后,我的所有尝试都失败了,我想最安全的(在所有Delphi版本中工作)解决方案如下。
Unit1 - Form1:TForm1 - fsMDIForm
Unit2 - Form2:TForm2 - fsMDIChild
Unit3 - AModalForm:TFom3 - ordinary form, shown modally, centered on the Form2
关键部分只是手动计算和设置Left
的{{1}}和Top
属性的后备,因此它会变为居中。它还要求将AModalForm
属性设置为Position
poDesigned