Reputation: 77
I made a form using a laptop which has 15 inches screen laptop but when i transfer the application to a notebook, some button components are invisible especially those below the form which were visible in the laptop. so is there a possibility of a code that makes the form adjust itself to fit in a notebook screen or how this can be done using properties?
Upvotes: 0
Views: 2339
Reputation: 14873
What you're asking for is also called resolution independence
which means to design your forms to make them usable on very small and very big screens (screen resolutions).
This is traditionally done using the Anchors
and Align
properties, so that controls can size and place themselves according to a certain layout.
Newer Delphi versions also have Margins
and AlignWithMargins
so that automatic alignment can reserve some space between controls.
Another way that is used by many other toolkits is to use an explicit layout concept. That can be done with TGridPanel
and TFlowPanel
in Delphi, but doesn't work very nice in my experience. There are better layout management systems out there (like DevExpress Layout Control).
You might also consider using TScrollBox
es, TSplitter
s and docking
to allow users to customize their UI experience.
You can also consider putting some functionality in extra dialogs that are called by buttons or hiding some controls on TPageControl
tab sheets.
Scaling is also possible (see Steves answer), but it makes forms appear odd and can drastically reduce the user experience, because controls become too small or users have hard time hitting the right control or fonts are too small, etc.
If the effort is to great or if you have totally different devices (like smart phones vs. workstations) it might even be necessary to have completly different forms or different apps that might use a client / server or multi tier architecture to share the same buisiness logic, but that's actually beyond the scope of this question...
Upvotes: 2
Reputation: 256
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.
Upvotes: 1