解决Delphi窗体缩放の疑难杂症
http://anony3721.blog.163.com/blog/static/511974201082235754423/
解决Delphi窗体缩放の疑难杂症
No.1 Delphi中如何限制窗体大小?
Delphi中可以限制窗体或者元件的大小,只要指定它的Constraints属性即可(默认是0,就是不限制)。但是Delphi这个属性有个很大的缺陷,比如从上往下调整,达到最小后,窗体高度虽然不会缩小了,但是窗体会继续往下移动,这样看起来会有些不正常(Delphi自己的窗体没有这个现象)。要解决这个问题,还是只有截取windows的消息,自己进行处理。
const
MinWidth = ;
MinHeight = ;
procedure WMSIZING(var Msg: TMessage); message WM_SIZING;
procedure TfrmMain.WMSIZING(var Msg: TMessage);
begin
Msg.Result := ;
//限制最小高度
if (PRect(Msg.LPARAM)^.Bottom - PRect(Msg.LPARAM)^.Top) < MinHeight then
begin
if PRect(Msg.LPARAM)^.Top = Top then
PRect(Msg.LPARAM)^.Bottom := PRect(Msg.LPARAM)^.Top + MinHeight
else
PRect(Msg.LPARAM)^.Top := PRect(Msg.LPARAM)^.Bottom - MinHeight;
end;
//限制最小宽度
if (PRect(Msg.LPARAM)^.Right - PRect(Msg.LPARAM)^.Left) < MinWidth then
begin
if PRect(Msg.LPARAM)^.Left = Left then
PRect(Msg.LPARAM)^.Right := PRect(Msg.LPARAM)^.Left + MinWidth
else
PRect(Msg.LPARAM)^.Left := PRect(Msg.LPARAM)^.Right - MinWidth;
end;
end;
找了很久,發現下面的寫法可以實現,在form改變大小時,畫面上的控件的相對位置不變,但控件的大小及控件上的文字大小隨之改變。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm1 = class(TForm)
Button1: TButton;
SpeedButton1: TSpeedButton;
procedure FormResize(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
FWidth: Integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormResize(Sender: TObject);
begin
ScaleBy(Width, FWidth);
FWidth := Width;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FWidth := Width;
end;
end.
delphi 程序窗体及控件自适应分辨率
代码如下:
unit untFixForm;
interface
uses
Classes, SysUtils, Controls, Forms;
type
TFontedControl = class(TControl)
public
property Font;
end;
TFontMapping = record
SWidth : Integer;
SHeight: Integer;
FName: string;
FSize: Integer;
end;
procedure FixForm(AForm: TForm);
procedure SetFontMapping;
var
FontMapping : array of TFontMapping;
implementation
procedure SetFontMapping;
begin
SetLength(FontMapping, 3);
// 800 x 600
FontMapping[0].SWidth := 800;
FontMapping[0].SHeight := 600;
FontMapping[0].FName := '宋体';
FontMapping[0].FSize := 7;
// 1024 x 768
FontMapping[1].SWidth := 1024;
FontMapping[1].SHeight := 768;
FontMapping[1].FName := '宋体';
FontMapping[1].FSize := 9;
// 1280 x 1024
FontMapping[2].SWidth := 1280;
FontMapping[2].SHeight := 1024;
FontMapping[2].FName := '宋体';
FontMapping[2].FSize := 11;
end;
procedure FixForm(AForm: TForm);
var
i, j : integer;
t : TControl;
begin
with AForm do
begin
for i := 0 to ComponentCount - 1 do
begin
try
t := TControl(Components[i]);
t.left := Trunc(t.left * (Screen.width / 1024));
t.top := Trunc(t.Top * (Screen.Height / 768));
t.Width := Trunc(t.Width * (Screen.Width / 1024));
t.Height := Trunc(t.Height * (Screen.Height / 768));
except
end; { try }
end; { for i }
for i:= 0 to Length(FontMapping) - 1 do
begin
if (Screen.Width = FontMapping[i].SWidth) and (Screen.Height = FontMapping[i].SHeight) then
begin
for j := 0 to ComponentCount - 1 do
begin
try
TFontedControl(Components[j]).Font.Name := FontMapping[i].FName;
TFontedControl(Components[j]).FONT.Size := FontMapping[i].FSize;
except
end; { try }
end; { for j }
end; { if }
end; { for i }
end; { with }
end;
initialization
SetFontMapping;
end.
SetFontMapping 方法可以自行修改,以适应更多的分辨率。
调用也非常简单,如下所示:
procedure TForm1.FormShow(Sender: TObject);
begin
if MessageBox(Handle,'要使用屏幕自适应吗?','提示',MB_YESNO or MB_ICONINFORMATION) = idno then Exit;
untFixForm.FixForm(Self);
end;
解决Delphi窗体缩放の疑难杂症的更多相关文章
- delphi 窗体自适应屏幕分辨率
delphi 窗体自适应屏幕分辨率 这是个困惑我很长时间的问题,到今天终于得到解决了. 话说Delphi有个很强的窗体设计器,这一点让VC粉丝垂涎三尺而不可得.但是,Delphi里设计的窗体并没有自动 ...
- C# winform中 窗体缩放自适应的方法(不同电脑/不同分辨率)
C# winform中 窗体缩放自适应的方法(不同电脑/不同分辨率) 窗体缩放是一个困扰我多时的问题,为了解决这个问题,我从网上找了很多相关的资料,很多人说用Anchor和Dock属性,但是我试了 ...
- 【Qt】Qt之自定义界面(窗体缩放-跨平台终极版)【转】
简述 通过上一节内容,我们实现了窗体的缩放,功能很不错,但是很遗憾-不支持跨平台!如果对于多平台来说,这是一个硬伤,所以,我们急需要一个能够支持跨平台的实现方案. 在网上看到过很多不同的实现方式,多多 ...
- 【Qt】Qt之自定义界面(窗体缩放)【转】
简述 通过前两节内容,我们实现了自定义窗体的移动,以及自定义标题栏-用来显示窗体的图标.标题,以及控制窗体最小化.最大化.关闭. 在这之后,我们还缺少窗体的缩放-当鼠标移动到窗体的边框-左.上.右.下 ...
- Qt之自定义界面(窗体缩放-跨平台终极版)
简述 通过上一节内容,我们实现了窗体的缩放,功能很不错,但是很遗憾-不支持跨平台!如果对于多平台来说,这是一个硬伤,所以,我们急需要一个能够支持跨平台的实现方案. 在网上看到过很多不同的实现方式,多多 ...
- Qt之自定义界面(窗体缩放)
简述 通过前两节内容,我们实现了自定义窗体的移动,以及自定义标题栏-用来显示窗体的图标.标题,以及控制窗体最小化.最大化.关闭. 在这之后,我们还缺少窗体的缩放-当鼠标移动到窗体的边框-左.上.右.下 ...
- delphi 窗体透明
TransparentColor:=true; TransparentColorValue:=clFuchsia; Color:= TransparentColorValue; ...
- Delphi窗体创建释放过程及单元文件小结(转)
Delphi窗体创建释放过程及单元文件小结 Delphi中的窗体,有模式窗体与非模式窗体两种.两种窗体的调用方式不同,模式窗体使用ShowModal显示,非模式窗体使用Show显示.当显示模式窗体的时 ...
- 解决mdi窗体闪烁的问题
/// 解决mdi窗体闪烁的问题 /// </summary> protected override CreateParams CreateParams { get { CreatePar ...
随机推荐
- 使用axios发送ajax请求
1.安装 npm install axios 2.在Home.vue中引入 import axios from 'axios' export default { name: 'Home', c ...
- DRF之三大认证
一.用户认证Authorticatons 1.源码解析 第一步. 找入口 def dispatch(self, request, *args, **kwargs): # 1.首先我们进入的是APIVi ...
- 2019-11-28-win10-uwp-提示-Cannot-find-a-Resource-with-the-Name-Key-找不到资源
title author date CreateTime categories win10 uwp 提示 Cannot find a Resource with the Name Key 找不到资源 ...
- Nginx1.3.15导致Wordpress,Drupal等框架无限重定向的解决方案
Wordpress建立的站点出现无限循环重定向问题.很多人遇到这个问题,并不是单纯Wordpress,Drupal, PHPCake等框架也都遇到同样的问题. 新版本的Nginx在收到 http:// ...
- hashlib模块和logging模块
hashlib Python的hashlib提供了常见的摘要算法,如MD5,SHA1等等. 我们以常见的摘要算法MD5为例,计算出一个字符串的MD5值: import hashlib m=hashli ...
- bzoj4326: NOIP2015 运输计划(二分+LCA+树上差分)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4326 题目大意:有一颗含有n个顶点的树,每两个点之间有一个边权,现在有m个运输计划,每个 ...
- 2019 ACM/ICPC 全国邀请赛(西安)J And And And (树DP+贡献计算)
Then n - 1n−1 lines follow. ii-th line contains two integers f_{a_i}(1 \le f_{a_i} < i)fai(1≤fa ...
- 六、ARM 寻址方式
寻址方式是针对源操作数来说的 6.1 立即数寻址 源操作数是立即数 立即数:操作码以 # 号开头的数字为立即数 立即数寻址: MOV R0, #0x300 伪指令: LDR R0 ...
- java:Conllection(List,set,get,map,subList)使用
list中的contains:是否包含指定元素 list中的SubList: 返回列表中指定的 fromIndex(包括 )和 toIndex(不包括)之间的部分视图. List<String ...
- 字符编码、python2和python3编码的区别
目录 字符编码 文本编辑器存储信息的过程 python解释器解释python代码的流程 python解释器与文本编辑器的异同 不同编码格式存入与读取数据的过程 乱码的分析 python2和python ...