实验四控件的属性_第1页
实验四控件的属性_第2页
实验四控件的属性_第3页
实验四控件的属性_第4页
实验四控件的属性_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、实验四 控件的属性、方法和事件的使用实验目的:1掌握键盘编程的常用事件2掌握鼠标编程的常用事件3掌握文本文件的常用操作过程和函数4掌握有类型文件的常用操作过程和函数实验内容:1识别鼠标是左键单击还是右键单击,并显示当前鼠标的位置。通过鼠标事件的过程参数来识别。procedure TForm1.onmousedown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var p:Tpoint;begingetcursorpos(p);if button=mbleft thenedit1.text:

2、=左键+X: + format(%d,p.x)+Y: + format(%d,p.y)elseedit1.text:=右键+X: + format(%d,p.x)+Y: + format(%d,p.y);end;end.2设计一程序,实现识别用户当前在键盘上按下的键。procedure TForm1.FormShortCut(var Msg: TWMKey; var Handled: Boolean);begin if Msg.CharCode=VK_TAB then begin showmessage(你按下了TAB键按下); end; if Msg.CharCode=VK_capital

3、then begin showmessage(你按下了capslock键按下);end; if Msg.CharCode=VK_f1 then begin showmessage(f1键按下);end; if Msg.CharCode=VK_f2 then begin showmessage(f2键按下); end; if Msg.CharCode=VK_f3 then begin showmessage(f3键按下); end; if Msg.CharCode=VK_f4 then begin showmessage(f4键按下); end; if Msg.CharCode=VK_f5 th

4、en begin showmessage(f5键按下); end; if Msg.CharCode=VK_f6 then begin showmessage(你按下了f6键); end; if Msg.CharCode=VK_f7 then begin showmessage(你按下了f7键); end; if Msg.CharCode=VK_f8 then begin showmessage(你按下了f8键); end; if Msg.CharCode=VK_f9 then begin showmessage(你按下了f9键); end; if Msg.CharCode=VK_f10 the

5、n begin showmessage(你按下了f10键); end; if Msg.CharCode=VK_f11 then begin showmessage(你按下了f11键); end; if Msg.CharCode=VK_f12 then begin showmessage(你按下了f12键); end; if Msg.CharCode=VK_LEFT then begin showmessage(你按下了left键); end; if Msg.CharCode=VK_right then begin showmessage(你按下了right键); end; if Msg.Cha

6、rCode=VK_up then begin showmessage(你按下了up键); end; if Msg.CharCode=VK_down then begin showmessage(你按下了down键); end; end;procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);beginif shift=ssshiftthenshowmessage(你按下了shift键);if shift=ssaltthenshowmessage(你按下了alt键);if shift=ssc

7、trlthenshowmessage(你按下了ctrl键);end;procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);begin messagedlg(你按下了+key+键。,mtinformation,mbok,0);end;end.3判断输入框是否全为数字,基本要求:设计一输入程序,其界面如图,身份证输入框限18位数字。输入框可输任意字符,是否全是数字由按钮键判别。procedure TForm1.onkeypress(Sender: TObject; var Key: Char);var Uflag: intege

8、r;begin Uflag:=Tedit(sender).Tag; if (not (key in 0.9) and (not (key=#8) then key:=#0;end;procedure TForm1.Button1Click(Sender: TObject);var i: LongInt; f: Double;begin if TryStrToInt(Edit2.Text,i) or TryStrToFloat(Edit2.Text, f) then ShowMessage(全是数字) else ShowMessage(不全是数字);end;end.4由键盘的方向键或鼠标控制图片

9、的移动。procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin moveFlag:=true; OX:=X; OY:=Y;end;procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin moveFlag:=False;end;procedure TForm1.Im

10、age1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);begin if moveFlag then begin Image1.Left:=Image1.Left+(X-OX); Image1.Top:=Image1.Top+(Y-OY); end;end;procedure TForm1.Button1Click(Sender: TObject);begin if imagelist.Execute then image1.Picture.LoadFromFile(Imagelist.FileName);end;pr

11、ocedure TForm1.Button2Click(Sender: TObject);begin close;end;end.实验五 自定义数据类型使用练习实验目的:1掌握数组的使用2掌握过程、函数的定义及使用方法3掌握指针类型的使用4掌握枚举子界集合类型的使用实验内容:1输入一串字符,统计字母、数字及汉字等的数量。procedure TForm1.Button1Click(Sender: TObject);varsource:string;ch:char;i,Zm,b,Zw,c:integer;begin source:=edit1.Text;Zm:=0; b:=0; Zw:=0; c:

12、=0;for i:=0 to length(source) do begin ch:=sourcei; case ch of A.Z,a.z:Zm:=Zm+1; 0.9:b:=b+1; chr(160).chr(3839):zw:=zw+1; chr(30).chr(47),chr(58).chr(64),chr(91).chr(96),chr(123).chr(127):c:=c+1; end; edit2.text:=inttostr(Zm); edit3.text:=inttostr(b); edit4.text:=inttostr(Zw div 2); edit5.text:=intt

13、ostr(c);end;end;procedure TForm1.Button2Click(Sender: TObject);begin close;end;end.2口袋有红黄蓝白黑五种颜色的球若干,每次从口袋中取出3个球。编写程序输出3种不同颜色球的所有取法。procedure TForm1.Button1Click(Sender: TObject);vari,j,k,sum:integer;varch1,ch2,ch3:string;begin i:=1;j:=1;k:=1; for i:=1 to 5 do begin for j:=1 to 5 do begin for k:=1 t

14、o 5 do begin if i=1 then ch1:=红; if i=2 then ch1:=蓝; if i=3 then ch1:=黄; if i=4 then ch1:=白; if i=5 then ch1:=黑; if j=1 then ch2:=红; if j=2 then ch2:=蓝; if j=3 then ch2:=黄; if j=4 then ch2:=白; if j=5 then ch2:=黑; if k=1 then ch3:=红; if k=2 then ch3:=蓝; if k=3 then ch3:=黄; if k=4 then ch3:=白; if k=5

15、then ch3:=黑; listbox1.items.add(inttostr(sum)+ch1+ch2+ch3); sum:=sum+1; end; end; end;end;3编写产生10个随机数装入数组,完成排序、逆向功能。vararr:array1.10of integer;$R *.dfmprocedure TForm1.Button1Click(Sender: TObject);vari:integer;begin for i:=1 to 9 do memo1.Lines i:=inttostr(arr10-i);end;procedure TForm1.Button2Click(Sender: TObject);vari,j,t,p,k:integer;begin memo2.Clear; for i:=1 to memo1.Lines.count-1 do begin k:=memo1.Lines.count-I; p:=memo1.Lines.count; for j:=1 to k do begin if(arrparrp-1)then begin t:=arrp; arrp:=arrp-1; arrp-1:=t; end; p:=p-1;

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论