DeWeb 电脑和手机动态适配

DeWeb 做多平台适配很方便!

多平台适配代码在OnMouseUp中。
X,Y分别表示当前设备的Width/Height;
Button : mbLeft : 屏幕纵向, mbRight:屏幕横向;
Shift:ssShift, ssAlt, ssCtrl,ssLeft, ssRight,
分别对应0:未知/1:PC/2:Android/3:iPhone/4:Tablet
另外,浏览窗体的
screenWidth可以通过dwGetProp(Self,'screenwidth')得到;
screenHeight可以通过dwGetProp(Self,'screenheight')得到;
innerWidth可以通过dwGetProp(Self,'innerwidth')得到;
innerHeight可以通过dwGetProp(Self,'innerheight')得到;
clientWidth可以通过dwGetProp(Self,'clientwidth')得到;
clientHeight可以通过dwGetProp(Self,'clientheight')得到;
其中:
screenWidth/screenHeight为屏幕分辨率。 注意:移动端为虚拟屏幕分辨率
innerWidth/innerHeight为可视区的宽高,包括了滚动条的宽度
clientWidth/clientHeight为可视区的宽高,不包括了滚动条的宽度

效果:http://www.web0000.com

`procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
iInnerW : Integer;
iRowCount : Integer;
iDemo : Integer;
//
oPanel : TPanel;
begin
//Shift:ssShift, ssAlt, ssCtrl,ssLeft, ssRight,
//分别对应0:未知/1:PC/2:Android/3:iPhone/4:Tablet

 if  (ssShift in Shift) or (ssAlt in Shift) then begin
      Width     := X-30;
      iInnerW   := StrToIntDef(dwGetProp(Self,'innerwidth'),-1);
      //
      if iInnerW = -1 then begin
           Exit;
      end;

      //
      Width     := iInnerW;

      if iInnerW < 1000 then begin
           Panel_Inner0.Width  := iInnerW;
      end else begin
           Panel_Inner0.Width  := 1000;
      end;
      Panel_Inner0.Left   := (Width - Panel_Inner0.Width) div 2;
      //
      Panel_Inner1.Width  := Panel_Inner0.Width;
      Panel_Inner1.Left   := Panel_Inner0.Left;
 end else begin
      if Y>X then begin
           //
           Width     := X;

           //
           Panel_All.Width     := X;

           //
           Panel_Inner0.Width  := X;
           Panel_Inner0.Left   := 0;
           Panel_Inner1.Width  := X;
           Panel_Inner1.Left   := 0;
           Panel_Inner2.Width  := X;
           Panel_Inner2.Left   := 0;
           Panel_Inner3.Width  := X;
           Panel_Inner3.Left   := 0;

           //hide components
           Edit_Search.Visible           := False;
           Button_Search.Visible         := False;
           Label_FAQs.Visible            := False;
           StaticText_FAQs.Visible       := False;
           Label_ContactUs.Visible       := False;
           StaticText_ContactUs.Visible  := False;

           //label : web develop with delphi
           Label_WDWD.Width              := X;
           Label_WDWD.Font.Size          := 18;
           Label_WDWD.Caption            := 'Web develop with Delphi';
           Label_WDWD.Left               := 0;

           //introduce labels
           Label_Introduce0.Left         := 8;
           Label_Introduce1.Left         := 8;
           Label_Introduce1.Caption      := '无需学习HTML/JavaScript/Java/PHP等新知识';
           Label_Introduce2.Left         := 8;

           //fee label
           Label_Fee.Left                := Label_BuyNow.Left + Label_BuyNow.Width;

           //buttons
           Button_Download.Left          := 10;
           Button_Download.Width         := (X-30) div 2;
           Button_Download.Caption       := 'Download';
           Button_BuyNow.Left            := Button_Download.Left + 10 + Button_Download.Width;
           Button_BuyNow.Width           := Button_Download.Width;

           //demos
           iRowCount := X div 180;
           Panel_03_Demos.Height    := Ceil(gjoDemos.A['items'].Count / iRowCount)*140;
           Panel_Inner3.Height      := Panel_03_Demos.Height;
           for iDemo := 0 to gjoDemos.A['items'].Count-1 do begin
                //get the demo panel include image and href(TStaticText)
                oPanel         := TPanel(FindComponent('Panel_Demo_'+IntToStr(iDemo)));
                oPanel.Top     := (iDemo div iRowCount) *140;
                oPanel.Left    := (iDemo mod iRowCount)* 180;

           end;

      end;
 end;
 //set total height
 Panel_All.Height    := Panel_99_Foot.Top + Panel_99_Foot.Height;
 dwSetHeight(self,Panel_All.Height);

end;
`

posted @ 2021-01-04 11:44  碧树西风Delphi  阅读(784)  评论(0)    收藏  举报