0、Lazarus官网
1、配置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属性
- 在对象查看器窗口选择Form1
- 第14项:
Caption
(窗口标题),改为关于 Everything
- 第28项:
Height
(窗口高度),改为300
- 倒数第2项:
Width
(窗口宽度),改为376
6.2 添加TPanel1
- 选择
Standard
-TPanel
,(自动显示预览窗口)
- 在预览窗口中点一下,就添加了一个
Panel1
- 确认组件的父子关系,如图
6.3 设置Panel1: TPanel属性
- 选择
Panel1
- 倒数第18项:
Left
(组件位置),改为-1
(设置为0会有一个白边) - 倒数第18项:
Top
(组件位置),改为-1
(0有白边) - 第28项:
Height
(组件高度),改为91
- 倒数第2项:
Width
(组件宽度),改为378
- 第15项:
Color
(组件颜色),改为clBlack
(向上划,第一项就是clBlack)
6.4 向Panel1中添加TStaticText1
- 选择
Additional
-TStaticText
- 在预览窗口中的Panel1部分点一下,就添加了一个
TStaticText
- 确认组件的父子关系,如图
- 如果位置不对,可以鼠标抓住
StaticText1
,拖到Panel1上方松手即可
6.5 设置StaticText1: TStaticText属性
- 选择
StaticText1
Left
,改为60
Top
,改为30
Height
,改为50
Width
,改为167
Caption
,改为Everything
- 展开第18项
Font
7.1Font
-Color
,改为clWhite
(第16项)
7.2Font
-Size
, 改为25
- 如图
6.6 添加TPanel2
- 组件父子图如下
6.7 设置TPanel2: TPanel属性
Left: -1
Top: 90
Width: 378
Height: 164
Font - Size: 8
清空Caption
6.8 向Panel2中添加3个TStaticText
这三个分别是StaticText2
、StaticText3
和StaticText4
- StaticText2
1.1 Left:60
、Top:18
、Width:150
、Height:50
1.2 点击Caption右侧的三个点打开编辑对话框,输入以下内容Everything 版本 V1.4.1.1022 (x64) Copyright © 2022 voidtools
- 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
- 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
- 如图
6.9 添加TPanel3
6.10 设置TPanel3: TPanel属性
Left: -1
、Top: 254
、Width: 378
、Height: 46
、清空Caption
6.11 向Panel3中添加3个TButton
- Button1
1.1 Left:16
、Top:12
、Width:74
、Height:22
1.2 Caption:许可证(L)
- Button2
2.1 Left:208
、Top:12
、Width:74
、Height:22
2.2 Caption:致谢(C)
- 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
- Form2属性:Height:
480
、Width:640
、Caption:许可证 - Everything
- ScrollBox1属性:Height:
480
、Width:640
、Left:0
、Top:0
2.1 展开HorzScrollBar,设置Visible为False,展开VertScrollBar,设置Increment值为32
- 向ScrollBox1添加组件StaticText1
- 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、修改代码
- 编辑Unit1,将
Form2.show();
的注释符号删除(代码在文章的8.6部分) - 添加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/