自已的一个小工具需要用到软键盘,就写成了个函数~看图
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, XPMan; type TForm1 = class(TForm) Panel1: TPanel; Button1: TButton; XPManifest1: TXPManifest; Memo1: TMemo; procedure FormCreate(Sender: TObject); procedure CreateKeyboard(myParent: TwinControl); procedure btnKeyClick(Sender: TObject); private btnKey: array[0..25] of TButton; { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.btnKeyClick(Sender: TObject); var letter: string; begin letter := LowerCase((Sender as TButton).Caption); if letter = 'space' then letter := ' '; Memo1.Lines.Text := Memo1.Lines.Text + letter; end; procedure TForm1.CreateKeyboard(myParent: TwinControl); //创建软键盘 var i, row, col: Integer; KeyMapping: array[0..25] of string; btnKey: array[0..25] of TButton; begin KeyMapping[0] := 'Q'; KeyMapping[1] := 'W'; KeyMapping[2] := 'E'; KeyMapping[3] := 'R'; KeyMapping[4] := 'T'; KeyMapping[5] := 'Y'; KeyMapping[6] := 'U'; KeyMapping[7] := 'I'; KeyMapping[8] := 'O'; KeyMapping[9] := 'P'; KeyMapping[10] := 'A'; KeyMapping[11] := 'S'; KeyMapping[12] := 'D'; KeyMapping[13] := 'F'; KeyMapping[14] := 'G'; KeyMapping[15] := 'H'; KeyMapping[16] := 'J'; KeyMapping[17] := 'K'; KeyMapping[18] := 'L'; KeyMapping[19] := 'Z'; KeyMapping[20] := 'X'; KeyMapping[21] := 'C'; KeyMapping[22] := 'V'; KeyMapping[23] := 'B'; KeyMapping[24] := 'N'; KeyMapping[25] := 'SPACE'; for i := 0 to 25 do begin btnKey[i] := TButton.Create(Self); btnKey[i].Parent := myParent; row := i div 10; col := i mod 10; if row = 0 then btnKey[i].Top := 7 else if row = 1 then btnKey[i].Top := 40 else if row = 2 then btnKey[i].Top := 73; if row = 0 then btnKey[i].Left := -8 + (col + 1) * 33 else if row = 1 then btnKey[i].Left := 15 + (col + 1) * 33 else if row = 2 then btnKey[i].Left := 35 + (col + 1) * 33 else btnKey[i].Left := -8 + (col) * 30; btnKey[i].Caption := KeyMapping[i]; btnKey[i].Height := 32; if i = 25 then btnKey[i].Width := 90 else btnKey[i].Width := 32; btnKey[i].OnClick := btnKeyClick; //按纽事件 end; end; procedure TForm1.FormCreate(Sender: TObject); begin CreateKeyboard(panel1); end; end.
标签:25,用到,KeyMapping,自已,else,软键盘,btnKey,col,row From: https://www.cnblogs.com/WilliamLv/p/17780644.html