窗体在不同分辨率下的大小和控件位置、变形问题:在800*600下做了一个FORM,但到640*480下一看却变了形,控件的相对位置都变了,不知道如何解决,请教诸位高手。Another_eYes (1998-11-22 22:39:29) implementation const ScreenWidth: LongInt = 800; {I designed my form in 800x600 mode.} ScreenHeight: LongInt = 600;{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject); begin scaled := true; if (screen.width <> ScreenWidth) then begin height := longint(height) * longint(screen.height) DIV ScreenHeight; width := longint(width) * longint(screen.width) DIV ScreenWidth; scaleBy(screen.width, ScreenWidth); end; end;下面是解决字体大小的代码: USES typinfo; {Add this to your USES statement.}var i: integer; begin for i := componentCount - 1 downto 0 do with components[i] do begin if GetPropInfo(ClassInfo, 'font') <> nil then font.size := (NewFormWidth DIV OldFormWidth) * font.size; end; end;下面的函数可以解决问题: Form:需要调整的Form,OrgWidth:开发时屏幕的宽度,OrgHeight:开发时屏幕的高度。 注意:需要把Form的Scaled设置为True。 procedure AdjustForm(Form: TForm; const OrgWidth, OrgHeight: integer); begin with Form do begin Width := Width * Screen.Width div OrgWidth; Height := Height * Screen.Height div OrgHeight; ScaleBy(Screen.Width, OrgWidth); end; end;
procedure TForm1.Button1Click(Sender: TObject); begin AdjustForm(Self,1280,1024); end;
在1024*768下开发的程序一调到800*600窗口与字体就变大,超出了原来设计时的布局,调了字体的类型各FORM的SCALED等,都没用,这种让FORM和其上控件都能随着分辨率调节的方法是不是只有写代码解决?假设你在800*600的分辨率下设计的form,第一步: inplementation const ScreenWidth: LongInt = 800; {I designed my form in 800x600 mode.} ScreenHeight: LongInt = 600;{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject); begin scaled := true; if (screen.width <> ScreenWidth) then begin height := longint(height) * longint(screen.height) div ScreenHeight; width := longint(width) * longint(screen.width) div ScreenWidth; scaleBy(screen.width, ScreenWidth); end; end;下一步,要让每个子控制的字体改变到合适的大小: type TFooClass = class(TControl); { needed to get at protected } { font property }var i: integer; begin for i := ControlCount - 1 downto 0 do TFooClass(Controls[i]).Font.Size := (NewFormWidth div OldFormWidth) * TFooClass(Controls[i]).Font.Size; end;
implementation
const
ScreenWidth: LongInt = 800; {I designed my form in 800x600 mode.}
ScreenHeight: LongInt = 600;{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
begin
scaled := true;
if (screen.width <> ScreenWidth) then begin
height := longint(height) * longint(screen.height) DIV ScreenHeight;
width := longint(width) * longint(screen.width) DIV ScreenWidth;
scaleBy(screen.width, ScreenWidth);
end;
end;下面是解决字体大小的代码:
USES typinfo; {Add this to your USES statement.}var
i: integer;
begin
for i := componentCount - 1 downto 0 do
with components[i] do
begin
if GetPropInfo(ClassInfo, 'font') <> nil then
font.size := (NewFormWidth DIV OldFormWidth) * font.size;
end;
end;下面的函数可以解决问题:
Form:需要调整的Form,OrgWidth:开发时屏幕的宽度,OrgHeight:开发时屏幕的高度。
注意:需要把Form的Scaled设置为True。
procedure AdjustForm(Form: TForm; const OrgWidth, OrgHeight: integer);
begin
with Form do
begin
Width := Width * Screen.Width div OrgWidth;
Height := Height * Screen.Height div OrgHeight;
ScaleBy(Screen.Width, OrgWidth);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
AdjustForm(Self,1280,1024);
end;
可不可以说得详细点。
比如怎么和Flash做好了界面怎么和Delphi接口。
要不要第三方控件等等问题
inplementation
const
ScreenWidth: LongInt = 800; {I designed my form in 800x600 mode.}
ScreenHeight: LongInt = 600;{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
begin
scaled := true;
if (screen.width <> ScreenWidth) then
begin
height := longint(height) * longint(screen.height) div ScreenHeight;
width := longint(width) * longint(screen.width) div ScreenWidth;
scaleBy(screen.width, ScreenWidth);
end;
end;下一步,要让每个子控制的字体改变到合适的大小:
type
TFooClass = class(TControl); { needed to get at protected }
{ font property }var
i: integer;
begin
for i := ControlCount - 1 downto 0 do
TFooClass(Controls[i]).Font.Size :=
(NewFormWidth div OldFormWidth) *
TFooClass(Controls[i]).Font.Size;
end;
Flash控件是个Ocx控件,提供了一些事件和方法,可以使你的Delphi程序与加载的Flash影片进行交互。
很多程序的安装程序都使用了Flash做界面,比如超级解霸。
关于如何和Flash交互你可以自己研究一下罗,很简单的。
用 ShockwaveFlash 控件,就可以无须考虑分辨率改变的问题了,全屏运行时,在程序里可以根据分辨率的变化动态调整 Flash 控件的大小,Flash 的内容是自动缩放的,而且是平滑缩放,效果很好。
我试过了,不行,如果窗体开始编译时大小是800*600,然后运行起来后全屏,那么我载入的flash还是以800*600显示。其他扩大的窗口如果你设置的Shockwaveflash的底色是黑色,那就全部是黑色。
可以的,是你没有处理好。
你想想看,Flash安装自带的那个播放器可以动态缩放,我们怎么办不到。