15 インチ画面のラップトップを搭載したラップトップを使用してフォームを作成しましたが、アプリケーションをノートブックに転送すると、一部のボタン コンポーネントが非表示になり、特にフォームの下にあるボタン コンポーネントがラップトップで表示されます。ノートブックの画面に収まるようにフォーム自体を調整するコードの可能性はありますか、またはプロパティを使用してこれを行う方法はありますか?
2 に答える
あなたが求めているのはresolution independence
、非常に小さな画面でも非常に大きな画面でも使えるようにフォームを設計するという意味でもあります (画面解像度)。
これは伝統的にAnchors
およびAlign
プロパティを使用して行われるため、コントロールは特定のレイアウトに従ってサイズ変更および配置できます。
Delphi の新しいバージョンにはMargins
andもありAlignWithMargins
、自動配置によりコントロール間にスペースを確保できます。
他の多くのツールキットで使用されているもう 1 つの方法は、明示的なレイアウトの概念を使用することです。これは Delphi で実行できますがTGridPanel
、TFlowPanel
私の経験ではうまく機能しません。より優れたレイアウト管理システムがあります ( DevExpress Layout Controlなど)。
ユーザーが UI エクスペリエンスをカスタマイズできるようにするためにTScrollBox
、es、TSplitter
s、およびの使用を検討することもできます。docking
TPageControl
ボタンによって呼び出される追加のダイアログにいくつかの機能を配置したり、タブ シートの一部のコントロールを非表示にしたりすることも検討できます。
スケーリングも可能ですが (Steves の回答を参照)、コントロールが小さすぎたり、ユーザーが適切なコントロールを押すのに苦労したり、フォントが小さすぎたりするなどの理由で、フォームが奇妙に見え、ユーザー エクスペリエンスが大幅に低下する可能性があります。
労力が大きすぎる場合、またはまったく異なるデバイス (スマートフォンとワークステーションなど) を使用している場合は、クライアント/サーバーまたは多層アーキテクチャを使用して同じビジネスを共有する、完全に異なるフォームまたは異なるアプリが必要になることさえあります。論理ですが、それは実際にはこの質問の範囲を超えています...
You might read the article by Zarko Gajic at http://delphi.about.com/od/standards/a/aa030700a.htm to understand some of the pitfalls in scaling.
Here is a function that might help:
procedure ScaleForm(theF: TForm; ScreenWidth, ScreenHeight: LongInt) ;
begin
theF.Scaled := True;
theF.AutoScroll := False;
if (Screen.Width <> ScreenWidth) then
begin
theF.Height :=LongInt(theF.Height) * LongInt(Screen.Height) div ScreenHeight;
theF.Width := LongInt(theF.Width) * LongInt(Screen.Width) div ScreenWidth;
theF.ScaleBy(Round(Screen.Width,ScreenWidth)) ;
end;
{the following lines work on an Xp PC but seem to have no effect on Win 7
theF.Position := poScreenCenter; //poDefault, poDesigned,poDesktopCenter,poOwnerFromCenter,poMainFormcenter
theF.Font.Name := 'Arial'; //to scale properly, you have to use a scalable font.
}
end;
Call the function in your application's OnCreate handler ScaleForm(Form1,screen.width,screen.height); Form1 is the handle of your form. Place the function call in a MENU item or button on your form to call it manually, if needed.
Also, here is a simple procedure using the ScaleBy function. ScaleBy can be used to adjust the form's size downward (or upward) in increments until the entire form fits on the Netbook. The example uses 10 percent increments. Depending on the controls you use in your application, this might be all you need. Many controls will scale automatically. There are more elegant and complicated solutions. In XE2 there is a function called ChangeScale which may be useful however it might not be available in Delphi 7. Remember, not all controls scale gracefully. You may have more work to do.
procedure TPktForm1.ScaleDown1Click(Sender: TObject);
begin
ScaleBy(90,100); //changes this form where ScaleBy(percentage reduction of reduced form, percentage original form);
Form_A.ScaleBy(90,100); //changes other forms in the application
Form_B.ScaleBy(90,100);
Application.ProcessMessages;
end;
or you might add Scaleby(659, Screen.Height ) in the form's OnCreate where '659' is the programmed original form height to fill a screen or Scaleby(Screen.Height, 659); to make the form smaller. Yes, there are limits to what this technique can do as far as down scaling. Going from desktop to Netbook works fine here.
There are plenty of examples on the Web. Are you using a DBGrid? You will have issues, however you can code around them for that control.