关于软件在不同分辨率下的兼容问题(200分)

  • 主题发起人 主题发起人 小天
  • 开始时间 开始时间

小天

Unregistered / Unconfirmed
GUEST, unregistred user!
好的软件应在不同分辨率下都有同样的效果,如加个Panel后,在800*600及640*480下,可使Form的版面不变。大家对此有什么其它好的方法及建议吗?
如,许多个label在Form上怎么放呢?
 
好问题,关注.
 
My classmate used ScaleBy() before to make his program fitted in both
800*600 and 1024*768, the effect, I thought, was good. You might try
this way.
 
Form的版面不变, 是什么意思?

在onCreate事件里用GetSystemMetrics()取得分辨率,再作显示内容的调整。
也可设置panel,label 的Align,Anchors属性。
 
>使Form的版面不变
要么设置form的scaled为false, 控制form的大小,
重载WM_GETMINMAXINFO消息,在该消息处理程序中,先得到主窗口CLIENTRECT区域
的RECT(应转成相对于SCREEN的位置),再用该信息填充消息的各个域。
typedef struct tagMINMAXINFO { // mmi
POINT ptReserved;
POINT ptMaxSize;
POINT ptMaxPosition;
POINT ptMinTrackSize;
POINT ptMaxTrackSize;
} MINMAXINFO;
设置好最大化时的位置用大小就行了。

要么就如前面的人所说的,
在设计时定好分辨率,如ox,oy;
在form.create时,用GetSystemMetrics取当前的分辨率,如nx,ny;
根据nx/ox,ny/oy来ScaleBy你的form及各可视控件。

我这有一个控件可实现,估计是用第二种方法实现的。
 
如果不想改变控件大小,只想重新调整位置呢?
 
仅为适应800X600,1024X768还可以在创建Form时对控件做一些调整,
困难的是同一分辨率大字体和小字体的自适应.
 
how about Large Font <--> Small Font?
 
大家看过一些查看股票的软件(windows95版)没有,
窗口减小变大,里面的字也同时缩放,
总之,无论是form,控件还是字体的比例关系总能保持不变。

我估计它是根据窗口的大小与原始窗口大小的比例,计算字的大小,
再用SetMapMode之类的API设置好显示参数, 来显示字的。

 
我经常遇到的问题是,比如我的form在Normal状态时,有2个水平并列放置的edit,
2个尺寸不一样大,当窗口调整时,这2个edit如何调整:是同时按比例缩放,还是只
缩放其中一个的尺寸? 如果同时按比例缩放,如果其中一个本来尺寸很小,岂不是
缩的看不见了?
 
http://www.torry.ru/vcl/forms/resscale.zip
ResScale v1.0 ??: Edward de la Rey (1998/01/12) (forms) resscale.zip
Allows multiple resolution screen design, with chosen components dimensions / positions saved /
restored from inifile / registry at runtime or design time.

http://www.torry.ru/vcl/forms/autosize.zip
Form AutoSize v0.1 ??: Robby Wachtel (1999/02/10) (forms) autosize.zip
FormAutoSize is a non-visual-component written to simplify the writing of Delphi applications for
different screen resolutions and fonts. Just put the component on the form and activate the settings you
will need.
 
特别是字体的自缩放问题,
如一个dbgrid要全屏显示,分辨率变小后如何继续全屏显示呢?
 
你应该把全部form版面用panel分割成几个板块,每个板块有自己的alLeft,alTop,
alClient属性,然后把所有控件都放在这些板块Panel上.
比如你把dbgrid放在一个align为alClient的Panel上,并且将Dbgrid的align也设
成alClient,这样,dbgrid会随着form的大小自动调整尺寸,而且不会影响到其他
的板块.
 
有resize控件.
 
不用控件,大家还有什么好建议吗?
 
小天,我刚回答一个类似问题,但那个方法没有测试,是一个老外说的,很简单.
摘抄如下:

前几天在一个国外站点看到说,对类似问题,只要:
form.font.Pitch:=fpVariable; //默认是fpDefault
就一了百了.

不过我没有测试,你可以试一试. :-)

 


你可以通过设置autoscroll属性为true来解决这个问题。但是这将引起更多的问题!
运行期间,DELPHI得到系统的屏幕分辨率并把它保存到Screen对象的 PixelsPerInch 属性中,接着DELPHI使用 PixelsPerInch 的值来确定当前分辨率下的窗口大小。
注意: 把FORM的Scaled属性设置为TRUE, TrueType fonts, use Windows small fonts when you develop, and set the AutoScroll property of your form(s) to FALSE.

另一种解决方案:

要使你写的应用程序在任何分辨率下的效果一样,可以如下编程:

implementation
const
ScreenWidth: LongInt = 800; {在分辨率为 800x600 的模式下编程.}
ScreenHeight: LongInt = 600;

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
scaled := true;
if (screen.width <> ScreenWidth) then

begin
//以下指form1的height &amp; width
height:=longint(height)*longint(screen.height) DIV ScreenHeight;
width := longint(width) * longint(screen.width) DIV ScreenWidth;
scaleBy(screen.width, ScreenWidth);
end;
end;


接着检查字体设置是否合适. 在修改font设置前,必须确保构件有此属性. 方法如下:

USES typinfo; {Add this to your USES statement.}

var
i: integer;
begin
for i := componentCount - 1 downto 0 do
with components do
begin
if GetPropInfo(ClassInfo, 'font') <> nil then
font.size := (NewFormWidth DIV OldFormWidth) * font.size;
end;
end;


* 设计程序时可设定窗口的scaled属性. 设为false的优点是运行时和设计时一致。 缺点是大小在不同分辨率下不一致。

1、 设置 Form确的 Scaled 属性为 True.

2、 设置 AutoScroll 为 False.

3、 设置字体为可缩放的字体:TrueType font, 比如:Arial. MS
San Serif , but remember that it is still a bitmapped font. Only Arial will give you a font within a pixel of the desired height. 注意: 如果该字体未在目标计算机安装,则WINDOWS将选择相近的字体,此时字体设置失效。

4、不要把窗口的position属性设置为poDesigned,因为分辨率不同将导致窗口的位置不同。

5、不要把构件堆积在一块,至少应有 4 pixels 的距离。

6、对于单行标签,如果它的align属性设置为 alLeft or alRight ,请设置
AutoSize 为 True. 否则设置为false.

7、 确保标签构件有足够的空间容纳变化了的字体 - a blank space that is 25% of the length of the current string display length is a little too much, but safe.
(You'll need at least 30% expansion space for string labels if you
plan to translate your app into other languages) If AutoSize is
False, make sure you actually set the label width appropriately. If AutoSize is True, make sure there is enough room for the label to grow on its own.

8、 In multi-line, word-wrapped labels, leave at least one line of
blank space at the bottom. You'll need this to catch the overflow
when the text wraps differently when the font width changes with
scaling. Don't assume that because you're using large fonts, you
don't have to allow for text overflow - somebody else's large fonts may be larger than yours!

9、 在不同分辨率下用DELPHI的IDE打开工程时,必须修改PixelsPerInch属性

10、 Speaking of component drift, don't rescale a form multiple times,at design time or a runtime. Each rescaling introduces roundoff errors which accumulate very quickly since coordinates are strictly integral. As fractional amounts are truncated off control's origins and sizes with each successive rescaling, the controls will appear to creep northwest and get smaller. If you want to allow your users to rescale the form any number of times, start with a freshly loaded/created form before each scaling, so that scaling errors do not accumulate.

11、 Don't change the PixelsPerInch property of the form, period.

12、 In general, it is not necessary to design forms at any particular resolution, but it is crucial that you review their appearance at 640x480 with small fonts and large, and at a high-resolution with small fonts and large before releasing your app. This should be part of your regular system compatibility testing checklist.

13、 Pay close attention to any components that are essentially
single-line TMemos - things like TDBLookupCombo. The Windows
multi-line edit control always shows only whole lines of text - if
the control is too short for its font, a TMemo will show nothing at all (a TEdit will show clipped text). For such components, it's
better to make them a few pixels too large than to be one pixel too
small and show not text at all.


14、 Keep in mind that all scaling is proportional to the difference in the font height between runtime and design time, NOT the pixel
resolution or screen size. Remember also that the origins of your
controls will be changed when the form is scaled - you can't very
well make components bigger without also moving them over a bit.
 
呵呵!我的办法比较老土:在Form的OnCreate中写:
while Font.Height > 15 do
Font.Size := Font.Size - 1;
while Font.Height < 15 do
Font.Size := Font.Size + 1;

结果您猜怎么着:灵!
 
后退
顶部