用Lazarus模仿Everything的关于窗口

0、Lazarus官网

https://www.lazarus-ide.org/

1、配置Lazarus编辑器

Lazarus开发环境配置

2、设置中文

菜单栏 - Tools - Options - Environment - General - Language
修改为 Chinese [zh_CH]
点击OK
菜单栏 - File - Restart

3、窗口找不到了?

情况一、按F12(源码编辑器切换好窗体源码,就是那个Unit1,Unit2,再按F12)
情况二、菜单栏 - 查看,每个选项挨个按(有看文字的功夫都按完一遍了,就挨个按就完了)

4、写代码的准备工作

创建文件夹,名为MyLazarusProject

5、新建图形界面的应用程序

在这里插入图片描述
菜单栏 - 工程(P) - 关闭工程
在这里插入图片描述
菜单栏 - 工程(P) - 新建工程
在这里插入图片描述
工程向导 - 新建工程(N)
在这里插入图片描述
选择应用程序,点击OK
在这里插入图片描述
菜单栏 - 文件(F) - 保存
选择之前创建的文件夹MyLazarusProject,点击打开,点击保存

6、开始拖窗口

6.1 设置Form1: TForm1属性

  1. 在对象查看器窗口选择Form1
  2. 第14项:Caption(窗口标题),改为关于 Everything
  3. 第28项:Height(窗口高度),改为300
  4. 倒数第2项:Width(窗口宽度),改为376

6.2 添加TPanel1

  1. 选择Standard - TPanel,(自动显示预览窗口)
    在这里插入图片描述
  2. 在预览窗口中点一下,就添加了一个Panel1
    在这里插入图片描述
  3. 确认组件的父子关系,如图
    在这里插入图片描述

6.3 设置Panel1: TPanel属性

  1. 选择Panel1
  2. 倒数第18项:Left(组件位置),改为-1(设置为0会有一个白边)
  3. 倒数第18项:Top(组件位置),改为-1(0有白边)
  4. 第28项:Height(组件高度),改为91
  5. 倒数第2项:Width(组件宽度),改为378
  6. 第15项:Color(组件颜色),改为clBlack(向上划,第一项就是clBlack)
    在这里插入图片描述

6.4 向Panel1中添加TStaticText1

  1. 选择Additional - TStaticText
    在这里插入图片描述
  2. 在预览窗口中的Panel1部分点一下,就添加了一个TStaticText
  3. 确认组件的父子关系,如图
    在这里插入图片描述
  4. 如果位置不对,可以鼠标抓住StaticText1,拖到Panel1上方松手即可

6.5 设置StaticText1: TStaticText属性

  1. 选择StaticText1
  2. Left,改为60
  3. Top,改为30
  4. Height,改为50
  5. Width,改为167
  6. Caption,改为Everything
  7. 展开第18项Font
    7.1 Font - Color,改为clWhite(第16项)
    7.2 Font - Size, 改为25
  8. 如图
    在这里插入图片描述

6.6 添加TPanel2

  1. 组件父子图如下
    在这里插入图片描述

6.7 设置TPanel2: TPanel属性

Left: -1 Top: 90
Width: 378 Height: 164
Font - Size: 8
清空Caption
在这里插入图片描述

6.8 向Panel2中添加3个TStaticText

在这里插入图片描述
这三个分别是StaticText2StaticText3StaticText4

  1. StaticText2
    1.1 Left: 60、Top: 18、Width: 150、Height: 50
    1.2 点击Caption右侧的三个点打开编辑对话框,输入以下内容
    Everything
    版本 V1.4.1.1022 (x64)
    Copyright © 2022 voidtools
    
  2. StaticText3
    2.1 Left: 60、Top: 68、Width: 150、Height: 17、Caption: david@voidtools.lazarus
    2.2 Font - Color: clBlue、Font - Style - fsUnderline: True
    2.3 Cursor: crHandPoint
  3. StaticText4
    3.1 Left: 60、Top: 85、Width: 150、Height: 17、Caption: https://www.voidtools.com/
    3.2 Font - Color: clBlue、Font - Style - fsUnderline: True
    3.3 Cursor: crHandPoint
  4. 如图
    在这里插入图片描述

6.9 添加TPanel3

在这里插入图片描述

6.10 设置TPanel3: TPanel属性

Left: -1、Top: 254、Width: 378、Height: 46、清空Caption

6.11 向Panel3中添加3个TButton

在这里插入图片描述
在这里插入图片描述

  1. Button1
    1.1 Left: 16、Top: 12、Width: 74、Height: 22
    1.2 Caption: 许可证(L)
  2. Button2
    2.1 Left: 208、Top: 12、Width: 74、Height: 22
    2.2 Caption: 致谢(C)
  3. Button3
    3.1 Left: 294、Top: 12、Width: 74、Height: 22
    3.2 Caption: 确定
    在这里插入图片描述

7、保存

菜单栏 - 文件(F) - 保存
选择之前创建的文件夹MyLazarusProject,点击打开,点击保存,点击保存再按一次

8、给组件添加点击事件

8.1.修改uses语句

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;

改为

uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, lclintf;

8.2.双击组件StaticText3,自动生成点击事件

procedure TForm1.StaticText3Click(Sender: TObject);
begin
  OpenURL('mailto:david@voidtools.lazarus');
end;

8.3.双击组件StaticText4,自动生成点击事件

procedure TForm1.StaticText4Click(Sender: TObject);
begin
  OpenURL('https://www.voidtools.com/');
end;

8.4.双击组件Button3,自动生成点击事件

procedure TForm1.Button3Click(Sender: TObject);
begin
  Close;
end;

8.5.双击组件Button2,自动生成点击事件

procedure TForm1.Button2Click(Sender: TObject);
begin
  Panel2.Visible := not Panel2.Visible ;
end;

8.6.双击组件Button1,自动生成点击事件(先注释一下,因为第二个窗口还没写)

procedure TForm1.Button1Click(Sender: TObject);
begin
  //Form2.show();
end;

9、新建第二个窗体

菜单栏 - 文件(F) - 新建窗体
选中Unit2,按F12调出预览窗口,添加滚动组件TScrollBox
在这里插入图片描述

  1. Form2属性:Height: 480、Width: 640、Caption: 许可证 - Everything
  2. ScrollBox1属性:Height: 480、Width: 640、Left: 0、Top: 0
    2.1 展开HorzScrollBar,设置Visible为False,展开VertScrollBar,设置Increment值为32
  3. 向ScrollBox1添加组件StaticText1
    在这里插入图片描述
  4. StaticText1属性:Left: 0、Top: 0
    4.1 展开Constraints,MaxHeight: 900、MaxWidth: 640、MinHeight: 900、MinWidth: 640
    4.2 Caption如下:
    
    Everything
    
    	Copyright (c) 2005-2017 David Carpenter
    	
    	Permission is hereby granted, free of charge, to any person obtaining a copy of
    	this software and associated documentation files (the "Software"), to deal in 
    	the Software without restriction, including without limitation the rights to 
    	use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
    	of the Software, and to permit persons to whom the Software is furnished to do
    	so, subject to the following conditions:
    	
    	The above copyright notice and this permission notice shall be included in all
    	copies or substantial portions of the Software.
    	
    	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
    	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
    	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
    	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
    	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
    	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
    	SOFTWARE.
    
    Perl-Compatible Regular Expressions
    
    	Copyright (c) 1997-2012 University of Cambridge
    	
    	Redistribution and use in source and binary forms, with or without
    	modification, are permitted provided that the following conditions are met:
    	
    	* Redistributions of source code must retain the above copyright notice,
    	  this list of conditions and the following disclaimer.
    	
    	* Redistributions in binary form must reproduce the above copyright
    	  notice, this list of conditions and the following disclaimer in the
    	  documentation and/or other materials provided with the distribution.
    	
    	* Neither the name of the University of Cambridge nor the names of its
    	  contributors may be used to endorse or promote products derived from
    	  this software without specific prior written permission.
    	
    	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    	AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    	ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    	LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    	CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    	POSSIBILITY OF SUCH DAMAGE.
    
    

10、修改代码

  1. 编辑Unit1,将Form2.show();的注释符号删除(代码在文章的8.6部分)
  2. 添加Form2窗口的引用(Unit2)
    uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, lclintf;
    
    改为
    uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, lclintf, Unit2;
    

11、保存

菜单栏 - 文件(F) - 保存
选择之前创建的文件夹MyLazarusProject,点击打开,点击保存

12、F9运行

在这里插入图片描述

13、unit1.pas代码

unit Unit1;

{$mode objfpc}{$H+}

interface

uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, lclintf, Unit2;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    StaticText1: TStaticText;
    StaticText2: TStaticText;
    StaticText3: TStaticText;
    StaticText4: TStaticText;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure StaticText3Click(Sender: TObject);
    procedure StaticText4Click(Sender: TObject);
  private

  public

  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.StaticText3Click(Sender: TObject);
begin
  OpenURL('mailto:david@voidtools.lazarus');
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Close;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Panel2.Visible := not Panel2.Visible;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.show();
end;

procedure TForm1.StaticText4Click(Sender: TObject);
begin
  OpenURL('https://www.voidtools.com/');
end;

end.

14、最终exe文件位置

.\MyLazarusProject\project1.exe
文件大小5460KB,EXE单文件,无引用无引擎,压缩还能降到1126KB

15、文档和社区

https://forum.lazarus.freepascal.org/index.php/board,13.0.html
https://wiki.lazarus.freepascal.org/


请添加图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值