(转)Inno Setup入门(十八)——Inno Setup类参考(4)
编辑框也叫文本框,是典型的窗口可视化组件,既可以用来输入文本,也可以用来显示文本,是程序设计中最常用的组件之一,可以获取用户输入的许多信息。Pascal中的编辑框由类Tedit实现,该类的定义如下:
TEdit = class(TCustomEdit)
property AutoSelect: Boolean; read write;
property AutoSize: Boolean; read write;
property BorderStyle: TBorderStyle; read write;
property CharCase: TEditCharCase; read write;
property Color: TColor; read write;
property Font: TFont; read write;
property HideSelection: Boolean; read write;
property MaxLength: Integer; read write;
property PasswordChar: Char; read write;
property ReadOnly: Boolean; read write;
property Text: String; read write;
property OnChange: TNotifyEvent; read write;
property OnClick: TNotifyEvent; read write;
property OnDblClick: TNotifyEvent; read write;
property OnKeyDown: TKeyEvent; read write;
property OnKeyPress: TKeyPressEvent; read write;
property OnKeyUp: TKeyEvent; read write;
end;
该类的层次模型如下:
下面的代码将演示创建编辑框,以及编辑框的Text属性:
[setup] AppName=Test AppVerName=TEST DefaultDirName="E:\TEST" AppVersion=1.0 [files] Source: "F:\desktop\Inno\ipmsg.exe";Flags:dontcopy [code] var myPage:TwizardPage; myBtn:TButton; ed1,ed2,ed3:TEdit; procedure ClickmyBtn(Sender: TObject); begin ed3.Text:=ed1.Text+' '+ed2.Text; end; procedure InitializeWizard(); begin myPage:=CreateCustomPage(wpWelcome, '标题:自定义页面', '描述:这是我的自定义页面'); myBtn:=TButton.Create(myPage); myBtn.Parent:=myPage.Surface; myBtn.Caption:='点我~'; myBtn.OnClick:=@ClickmyBtn; ed1:=TEdit.Create(myPage); ed1.Parent:=myPage.Surface; ed1.Top:=myBtn.Top+30; ed1.Width:=myBtn.Width; ed2:=TEdit.Create(myPage); ed2.Parent:=myPage.Surface; ed2.Top:=ed1.Top+30; ed2.Width:=myBtn.Width; ed3:=TEdit.Create(myPage); ed3.Parent:=myPage.Surface; ed3.Top:=ed2.Top+30; ed3.Width:=myBtn.Width; end; |
属性Text用于设置或获取文本框中的内容,注意不管是设置还是获取,参数一定必须是String的类型,运行效果如下:
如果是想实现两个数的代数运算,而不是字符串的拼接,则按钮的OnClick过程应该做如下修改:
procedure ClickmyBtn(Sender: TObject); var a,b:Extended; begin a:=StrToFloat(ed1.Text); b:=StrToFloat(ed2.Text); ed3.Text:=FloatToStr(a+b); end; |
StrToFloat和FloatToStr分别实现字符串转实数,实数转字符串。在第一、第二个文本框中输入数值后,点击按钮将第三个文本框中的内容设置为两数的和。下面再说说其他的属性。修改代码段如下:
[code] var myPage:TwizardPage; myBtn:TButton; ed1,ed2,ed3:TEdit; a,b,c:String; procedure ClickmyBtn(Sender: TObject); begin a:=ed1.Text; b:=ed2.Text; c:=a+b; ed3.Text:=c; end; procedure InitializeWizard(); begin myPage:=CreateCustomPage(wpWelcome, '标题:自定义页面', '描述:这是我的自定义页面'); myBtn:=TButton.Create(myPage); myBtn.Parent:=myPage.Surface; myBtn.Caption:='点我~'; myBtn.OnClick:=@ClickmyBtn; ed1:=TEdit.Create(myPage); ed1.Parent:=myPage.Surface; ed1.Top:=myBtn.Top+30; ed1.Width:=myBtn.Width; ed1.CharCase:=ecUpperCase;{大写} ed1.ShowHint:=True; ed1.Hint:='字母将会变为大写'; ed2:=TEdit.Create(myPage); ed2.Parent:=myPage.Surface; ed2.Top:=ed1.Top+30; ed2.Width:=myBtn.Width; ed2.PasswordChar:='#';{密码样式} ed3:=TEdit.Create(myPage); ed3.Parent:=myPage.Surface; ed3.Top:=ed2.Top+30; ed3.Width:=myBtn.Width*2; ed3.ReadOnly:=true;{只读} end; |
上面介绍了四个属性:CharCase将设置文本显示的格式,可以有三个值:(ecNormal, ecUpperCase, ecLowerCase,分别为正常方式,大写方式,小写方式;PasswordChar属性将输入的文本替换为制定的样式;ReadOnly属性将使得该文本框不接受用户输入;Hint和ShowHint属性是用户的鼠标停留在该文本框上时,给出相应的提示文本,注意只有在ShowHint设置为True的时候才会显示。
另外,编辑框也能对一些事件做出相应,例如单击、双击,文本内容发生变化等,实现起来和按钮的差不错,这里就不再啰嗦了。最后需要介绍的是三个处理按键的属性: OnKeyDown、OnKeyPress和OnKeyUp
这三个属性是当用户光标停留在该文本框中时,当用户按下了键盘上的某个键时,会调用该属性指定的过程,测试代码如下:
[code] var myPage:TwizardPage; ed:TEdit; procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (key=67) and (Shift=[ssAlt]) then Msgbox('你按下了Alt+c',MBInformation,MB_OK); end; procedure InitializeWizard(); begin myPage:=CreateCustomPage(wpWelcome, '标题:自定义页面', '描述:这是我的自定义页面'); ed:=TEdit.Create(myPage); ed.Parent:=myPage.Surface; ed.OnKeyDown:=@EditKeyDown; end; |
在编辑框中输入时,用户按下Alt+C组合时,将会做出响应,弹出一个消息框,这样可以对我们感兴趣的按键组合做出相应的动作,例如我们想屏蔽粘贴这项功能,则修改代码如下:
procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (key=86) and (Shift=[ssCtrl]) then Msgbox('粘贴无效,请手动输入',MBInformation,MB_OK); ed.text:=''; end; |
不过这里要说明的是,这还不能屏蔽右键粘贴,只是屏蔽了Ctrl+V的方式。另外两个按键属性和这里介绍的KeyDown差不多,可对照测试一下。
(转)Inno Setup入门(十八)——Inno Setup类参考(4)的更多相关文章
- Inno Setup入门(八)——有选择性的安装文件
这主要使用[Components]段实现,一个演示的代码如下: [setup] ;全局设置,本段必须 AppName=Test AppVerName=TEST DefaultDirName=" ...
- Inno Setup入门(八)——有选择性的安装文件
这主要使用[Components]段实现,一个演示的代码如下: [setup] ;全局设置,本段必须 AppName=Test AppVerName=TEST DefaultDirName=" ...
- (转)Inno Setup入门(八)——有选择性的安装文件
本文转载自:http://blog.csdn.net/yushanddddfenghailin/article/details/17250827 这主要使用[Components]段实现,一个演示的代 ...
- [译]Kinect for Windows SDK开发入门(十八):Kinect Interaction交互控件
本文译自 http://dotneteers.net/blogs/vbandi/archive/2013/03/25/kinect-interactions-with-wpf-part-i-getti ...
- Android入门(十八)服务
原文链接:http://www.orlion.ga/674/ 一.定义一个服务 创建一个项目ServiceDemo,然后在这个项目中新增一个名为 MyService的类,并让它继承自 Service, ...
- [WebGL入门]十八,利用索引缓存来画图
注:文章译自http://wgld.org/.原作者杉本雅広(doxas),文章中假设有我的额外说明.我会加上[lufy:].另外,鄙人webgl研究还不够深入,一些专业词语,假设翻译有误,欢迎大家指 ...
- Inno Setup入门(一)——最简单的安装脚本
地址:http://379910987.blog.163.com/blog/static/3352379720110238252326/ 一个最简单的安装脚本: 1.最简单的安装文件脚本: [setu ...
- Inno Setup入门(十六)——Inno Setup类参考(2)
Inno Setup入门(十六)——Inno Setup类参考(2) http://379910987.blog.163.com/blog/static/33523797201112755641236 ...
- Inno Setup入门(十五)——Inno Setup类参考(1)
分类: Install Setup 2013-02-02 11:27 536人阅读 评论(0) 收藏 举报 nno setup脚本能够支持许多的类,这些类使得安装程序的功能得到很大的加强,通过对这些类 ...
- (转)Inno Setup入门(十五)——Inno Setup类参考(1)
本文转载自:http://blog.csdn.net/yushanddddfenghailin/article/details/17250955 nno setup脚本能够支持许多的类,这些类使得安装 ...
随机推荐
- bzoj3600
题解: 好像是什么替罪羊树 然后看了几个题解 然后就抄了一边 代码: #include<bits/stdc++.h> using namespace std; ; int n,m,rt,R ...
- CF910B
题解: dp f[i][j]表示i根a,j根b要多少 然后随便转移一下 代码: #include<bits/stdc++.h> using namespace std; ][],n,a,b ...
- windows 2008 server R2 服务器docker安装
1.安装包选择 windows win10 较新版本,使用 Get Docker for Windows (Stable) 或者 Get Docker for Windows (Edge) 其余使用 ...
- SpringInAction--Spring Web应用之SpringMvc 注解配置
Spring MVC 是当前Web服务器中常用的结构,今天就来学习这相关的知识,首先上图——Spring请求的时候所经历的坎坷之路: (书上原话,算是解释..) 在请求离开浏览器时① ,会带有用户所请 ...
- Linux设备驱动——简单的字符驱动
本文介绍Linux字符设备的静态注册方法, 其中涉及到的模块加载,不了解的可以先参考 构建和运行模块 1. 还是线上源代码: //memdev.h #ifndef _MEMDEV_H_ #define ...
- L152
For the first time, one of the new immunotherapy drugs has shown promise against breast cancer in a ...
- 【dlbook】实践方法论
[性能度量] 使用什么误差度量? 目标性能大致为多少? [默认的基准模型] 首先尝试分段线性单元,ReLU以及扩展. SGD一般是合理的选择,选加入动量的版本,衰减方法不一. 批标准化在优化出现问题时 ...
- CString与输入输出流对象问题。
在C++ 编程出现:cin>>Id;没有与这些操作匹配的">>"运算符: 你要看你的Id的数据类型,如果是CString等字符串,要用cin.getline ...
- for循环打印等腰三角形、直角三角形、菱形
一.等腰三角形 package s1; import java.util.Scanner; public class C31 { public static void main(String[] ar ...
- 《利用Python进行数据分析》笔记---第2章--1880-2010年间全美婴儿姓名
写在前面的话: 实例中的所有数据都是在GitHub上下载的,打包下载即可. 地址是:http://github.com/pydata/pydata-book 还有一定要说明的: 我使用的是Python ...