From b98b0d909a7ae1740e59cb164969dd33559c00cb Mon Sep 17 00:00:00 2001 From: cz_012273 Date: Sat, 29 Jul 2023 16:13:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=B0=E4=BA=8B=E6=9C=AC?= =?UTF-8?q?=E6=A8=AA=E5=B1=8F=E7=95=8C=E9=9D=A2=EF=BC=88=E5=88=86=E5=88=AB?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E6=A8=AA=E7=AB=96=E5=B1=8F=E5=B8=83=E5=B1=80?= =?UTF-8?q?=EF=BC=89=EF=BC=8C=E5=A4=84=E7=90=86=E8=99=9A=E6=8B=9F=E9=94=AE?= =?UTF-8?q?=E7=9B=98=E6=89=93=E5=BC=80=E6=97=B6=E6=97=8B=E8=BD=AC=E5=B1=8F?= =?UTF-8?q?=E5=B9=95=E5=87=BA=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=88?= =?UTF-8?q?=E7=94=A8close=E5=91=BD=E4=BB=A4=E9=80=80=E5=87=BA=E8=99=9A?= =?UTF-8?q?=E6=8B=9F=E9=94=AE=E7=9B=98=E7=BC=96=E8=BE=91=E7=8A=B6=E6=80=81?= =?UTF-8?q?=EF=BC=89=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MainForm.pas | 2 +- MyDelphi.dproj | 10 ++-- Unit1.LgXhdpiPh.fmx | 8 +++ Unit1.pas | 110 ++++++++++++++++++++++++++++++++++++----- mainform.LgXhdpiPh.fmx | 15 +++--- 5 files changed, 121 insertions(+), 24 deletions(-) diff --git a/MainForm.pas b/MainForm.pas index 125dcea..7303f5d 100644 --- a/MainForm.pas +++ b/MainForm.pas @@ -194,7 +194,7 @@ end; procedure TToolsForm.ComboBox1ClosePopup(Sender: TObject); begin - ComboBox1.resetfocus; + ComboBox1.resetfocus; //ComboBox1澶卞幓鐒︾偣 end; procedure TToolsForm.DisplayRationale(Sender: TObject; diff --git a/MyDelphi.dproj b/MyDelphi.dproj index b7f7159..4769c8d 100644 --- a/MyDelphi.dproj +++ b/MyDelphi.dproj @@ -346,23 +346,23 @@ true - + - ic_notification.png true - + true - + + ic_notification.png true - + true diff --git a/Unit1.LgXhdpiPh.fmx b/Unit1.LgXhdpiPh.fmx index bff3b38..40fdb1a 100644 --- a/Unit1.LgXhdpiPh.fmx +++ b/Unit1.LgXhdpiPh.fmx @@ -2,6 +2,7 @@ inherited Form1_LgXhdpiPh: TForm1_LgXhdpiPh ClientHeight = 720 ClientWidth = 450 FormFactor.Height = 720 + OnResize = DoOrientationChanged OnShow = Formshow DesignerMasterStyle = 3 inherited Image1: TImage @@ -19,37 +20,44 @@ inherited Form1_LgXhdpiPh: TForm1_LgXhdpiPh Viewport.Height = 498.000000000000000000 end inherited Button1: TButton + Anchors = [akTop] StyledSettings = [Family, Size, Style] Position.X = 371.000000000000000000 Size.Width = 80.000000000000000000 TextSettings.FontColor = claDarkgreen end inherited Filedelete: TButton + Anchors = [] Position.X = 6.000000000000000000 Position.Y = 665.000000000000000000 Size.Width = 165.000000000000000000 end inherited FileExit: TButton + Anchors = [] Position.X = 278.000000000000000000 Position.Y = 665.000000000000000000 Size.Width = 165.000000000000000000 end inherited FileNew: TButton + Anchors = [] Position.X = 6.000000000000000000 Position.Y = 537.000000000000000000 Size.Width = 165.000000000000000000 end inherited FileOpen: TButton + Anchors = [] Position.X = 278.000000000000000000 Position.Y = 537.000000000000000000 Size.Width = 165.000000000000000000 end inherited FileSave: TButton + Anchors = [] Position.X = 6.000000000000000000 Position.Y = 601.000000000000000000 Size.Width = 165.000000000000000000 end inherited FileSaveAs: TButton + Anchors = [] Position.X = 278.000000000000000000 Position.Y = 601.000000000000000000 Size.Width = 165.000000000000000000 diff --git a/Unit1.pas b/Unit1.pas index ce581cf..3afb295 100644 --- a/Unit1.pas +++ b/Unit1.pas @@ -4,7 +4,7 @@ interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, - System.Variants, + System.Variants,FMX.VirtualKeyboard, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Memo.Types, FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo, FMX.Layouts, FMX.StdCtrls, System.IOUtils, FMX.Objects, FMX.Ani, FMX.Effects, System.DateUtils, Posix.Unistd; @@ -36,6 +36,7 @@ type procedure FiledeleteMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single); procedure Memo1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Single); + procedure DoOrientationChanged(Sender: TObject); private { Private declarations } @@ -65,7 +66,7 @@ implementation uses {$IFDEF ANDROID} {$ENDIF} - MyDialogs; + MyDialogs,FMX.Platform; type TTextFormat = (tfAnsi, tfUnicode, tfUnicodeBigEndian, tfUtf8); @@ -74,6 +75,8 @@ var today: Cardinal; selstart: integer; sellength: integer; + screenstate:integer; + const // TextFormatFlag: array[tfAnsi..tfUtf8] of word=($0000,$FFFE,$FEFF,$EFBB); @@ -81,8 +84,10 @@ const $BBEF); // 编码标志高低字节互换 {$R *.fmx} + {$R *.LgXhdpiPh.fmx ANDROID} + resourcestring sSaveChanges = '是否将未更改保存到 %s?'; sOverWrite = '%s 已存在。' + #13#10 + '要替换它吗?'; @@ -91,6 +96,85 @@ resourcestring sColRowInfo = 'Line: %3d Col: %3d'; sCommonDlgFileName = '文本文档(*.txt)|*.txt|所有文件(*.*)|*.*'; +procedure TForm1.DoOrientationChanged(Sender: TObject); +var + screenService: IFMXScreenService; + Keyboard: IFMXVirtualKeyboardService; +begin + if Assigned(Label_A) and Assigned(Button_A) then + begin + if TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService,Keyboard) then + begin + if TVirtualKeyBoardState.Visible in Keyboard.GetVirtualKeyBoardState then + begin + Keyboard.HideVirtualKeyboard; //关闭虚拟键盘 + end + end; + Close; //使编辑框失去焦点 + Label_A.visible:=false; + Label_B.visible:=false; + Button_A.visible:=false; + Button_B.visible:=false; + end; + + if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, screenService) then begin + case screenService.GetScreenOrientation of + TScreenOrientation.Portrait: //竖屏状态 + begin + screenstate:=1; + memo1.height:=480; + memo1.width:=344; + button1.position.x:=275; + filenew.position.x:=6;filenew.position.y:=527; + filesave.position.x:=6;filesave.position.y:=591; + filedelete.position.x:=6;filedelete.position.y:=655; + fileopen.position.x:=188;fileopen.position.y:=527; + filesaveas.position.x:=188;filesaveas.position.y:=591; + fileexit.position.x:=188;fileexit.position.y:=655; + end; + TScreenOrientation.Landscape: //横屏状态 + begin + screenstate:=2; + memo1.height:=328; + memo1.width:=532; + button1.position.x:=463; + filenew.position.x:=555;filenew.position.y:=10; + filesave.position.x:=555;filesave.position.y:=70; + filedelete.position.x:=555;filedelete.position.y:=130; + fileopen.position.x:=555;fileopen.position.y:=190; + filesaveas.position.x:=555;filesaveas.position.y:=250; + fileexit.position.x:=555;fileexit.position.y:=310; + end; + TScreenOrientation.InvertedPortrait: //倒竖屏状态 + begin + screenstate:=3; + memo1.height:=480; + memo1.width:=344; + button1.position.x:=275; + filenew.position.x:=6;filenew.position.y:=527; + filesave.position.x:=6;filesave.position.y:=591; + filedelete.position.x:=6;filedelete.position.y:=655; + fileopen.position.x:=188;fileopen.position.y:=527; + filesaveas.position.x:=188;filesaveas.position.y:=591; + fileexit.position.x:=188;fileexit.position.y:=655; + end; + TScreenOrientation.InvertedLandscape: //倒横屏状态 + begin + screenstate:=4; + memo1.height:=328; + memo1.width:=532; + button1.position.x:=463; + filenew.position.x:=555;filenew.position.y:=10; + filesave.position.x:=555;filesave.position.y:=70; + filedelete.position.x:=555;filedelete.position.y:=130; + fileopen.position.x:=555;fileopen.position.y:=190; + filesaveas.position.x:=555;filesaveas.position.y:=250; + fileexit.position.x:=555;fileexit.position.y:=310; + end; + end; + end; +end; + procedure TForm1.SetFileName(const FileName: String); begin FFileName := System.IOUtils.Tpath.GetSharedDocumentsPath + '/' + @@ -259,7 +343,7 @@ begin Label_B.free; Button_A.free; Button_B.free; - Memo1.height := 510; // 将meno控件恢复到默认高度 + Memo1.height := 480; // 将meno控件恢复到默认高度 Memo1.Lines.clear; end; FWantExit := True; @@ -289,20 +373,24 @@ end; procedure TForm1.Memo1MouseLeave(Sender: TObject); // 改变memo1高度以适应虚拟键盘 var i: integer; -const - halfscreen :integer = 403; //显示输入法界面后的memo高度 + halfscreen :integer; //显示输入法界面后的memo高度 begin i := Memo1.selstart; // showmessage(inttostr(i)); - if (i>0) and (Memo1.height > 430) then + if (screenstate=2)or(screenstate=4) then + halfscreen := 298 + else + halfscreen := 403; + + if (i>0) and (Memo1.height > halfscreen) then begin Memo1.height := halfscreen; Memo1.selstart := i; //创建显示行、列号标签 - Label_A := tlabel.Create(Self); + if not Assigned(Label_A) then Label_A := tlabel.Create(Self); with Label_A do begin Parent := Self; @@ -314,7 +402,7 @@ begin Visible := true; end; - Label_B := tlabel.Create(Self); + if not Assigned(Label_B) then Label_B := tlabel.Create(Self); with Label_B do begin Parent := Self; @@ -328,7 +416,7 @@ begin //创建滚动条加速按钮 - Button_A := tButton.Create(Self); + if not Assigned(Button_A) then Button_A := tButton.Create(Self); with Button_A do begin Parent := Self; @@ -341,7 +429,7 @@ begin onclick := Button_A_Click; //设置点击事件 end; - Button_B := tButton.Create(Self); + if not Assigned(Button_B) then Button_B := tButton.Create(Self); with Button_B do begin Parent := Self; @@ -356,7 +444,7 @@ begin end; - if Memo1.height = halfscreen then //动态更新行列号 + if (Memo1.height = halfscreen) and (Assigned(Label_A)) then //动态更新行列号 begin Label_A.Text := '当前行号:'+IntToStr(Memo1.CaretPosition.line+1); Label_B.Text := '当前列号:'+IntToStr(Memo1.CaretPosition.Pos+1); diff --git a/mainform.LgXhdpiPh.fmx b/mainform.LgXhdpiPh.fmx index 36e674a..4d9e609 100644 --- a/mainform.LgXhdpiPh.fmx +++ b/mainform.LgXhdpiPh.fmx @@ -32280,6 +32280,7 @@ inherited ToolsForm_LgXhdpiPh: TToolsForm_LgXhdpiPh end inherited Panel1: TPanel Position.X = 16.000000000000000000 + Size.Width = 330.000000000000000000 Size.Height = 305.000000000000000000 inherited Label1: TLabel StyledSettings = [Family, Style, FontColor] @@ -32294,7 +32295,7 @@ inherited ToolsForm_LgXhdpiPh: TToolsForm_LgXhdpiPh inherited Label3: TLabel StyledSettings = [Family, Style, FontColor] Position.X = 7.000000000000000000 - Position.Y = 180.000000000000000000 + Position.Y = 170.000000000000000000 Size.Width = 50.000000000000000000 Size.Height = 25.000000000000000000 Text = #25628#32034 @@ -32302,7 +32303,7 @@ inherited ToolsForm_LgXhdpiPh: TToolsForm_LgXhdpiPh inherited Label2: TLabel StyledSettings = [Family, Style, FontColor] Position.X = 7.000000000000000000 - Position.Y = 102.000000000000000000 + Position.Y = 97.000000000000000000 Size.Width = 50.000000000000000000 Size.Height = 25.000000000000000000 TextSettings.Font.Size = 24.000000000000000000 @@ -32310,13 +32311,13 @@ inherited ToolsForm_LgXhdpiPh: TToolsForm_LgXhdpiPh end inherited Edit2: TEdit Position.X = 72.000000000000000000 - Position.Y = 175.000000000000000000 + Position.Y = 165.000000000000000000 Size.Width = 250.000000000000000000 end inherited Edit1: TEdit Text = 'www.baidu.com' Position.X = 72.000000000000000000 - Position.Y = 97.000000000000000000 + Position.Y = 92.000000000000000000 Size.Width = 250.000000000000000000 end inherited ComboBox1: TComboBox @@ -32329,12 +32330,12 @@ inherited ToolsForm_LgXhdpiPh: TToolsForm_LgXhdpiPh inherited SpeedButton1: TSpeedButton AutoTranslate = False Position.X = 24.000000000000000000 - Position.Y = 250.000000000000000000 + Position.Y = 240.000000000000000000 OnClick = SpeedButton1Click end inherited SpeedButton2: TSpeedButton - Position.X = 200.000000000000000000 - Position.Y = 250.000000000000000000 + Position.X = 202.000000000000000000 + Position.Y = 240.000000000000000000 end end end -- GitLab