📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit3: TEdit;
Button1: TButton;
Label4: TLabel;
Label5: TLabel;
procedure ComboBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure ComboBox1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.ComboBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
AntiStart_1,AntiLength_1,AntiStart_2,AntiLength_2:Integer;
begin
if Key =13 then
Edit1.Text:=ComboBox1.SelText;
AntiStart_1:=0;
AntiLength_1:=ComboBox1.SelStart;
AntiStart_2:=ComboBox1.SelStart+ComboBox1.SelLength+1;
AntiLength_2:= Length(ComboBox1.Text)
-(ComboBox1.SelStart+ComboBox1.SelLength);
Edit2.Text:=Copy(ComboBox1.Text,AntiStart_1,AntiLength_1)
+Copy(ComboBox1.Text,AntiStart_2,AntiLength_2);
end;
procedure TForm1.ComboBox1Click(Sender: TObject);
begin
Label4.Caption:='所选的是:'+#13
+ComboBox1.Items.Strings[ComboBox1.ItemIndex];
end;
procedure TForm1.Button1Click(Sender: TObject);
var
X,tmpIndex:Integer;
ifExist:Boolean;
begin
tmpIndex:=0;
ifExist:=False;
for X:=0 to ComboBox1.Items.Count-1 do
if ComboBox1.Items.Strings[X]=Edit3.Text then
begin
tmpIndex:=X;
ifExist:=True;
end;
if not ifExist then
begin
ComboBox1.Items.Add(Edit3.Text);
ComboBox1.ItemIndex:=ComboBox1.Items.Count-1;
end
else
begin
ShowMessage('早就有资料啦!');
ComboBox1.ItemIndex:=tmpIndex;
end;
ComboBox1.SetFocus;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -