完全解决方案
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DBCtrls, DB, ExtCtrls, Grids, DBGrids, DBTables, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
procedure KillRigthButton(var Msg: TMsg; var Handled: Boolean);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
application.OnMessage := KillRigthButton;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
//允许输入float值
if not (Key in ['0'..'9',chr(VK_BACK), chr(VK_LEFT),chr(VK_RIGHT),
chr(VK_TAB),chr(46)]) Then Key:=#0;
if (key=chr(46)) and (pos('.',(sender as TEdit).Text)>0) then Key:=#0;
//加入这句可以限制输入的位数
if (Length(Trim((sender as TEdit).Text))>=15) and (Key<>chr(VK_BACK)) then Key:=#0;
end;
procedure TForm1.KillRigthButton(var Msg: TMsg; var Handled: Boolean);
begin
//防止右键弹出复制对话框
if Msg.hwnd = edit1.Handle then
if Msg.message = wm_rbuttonup then
Handled := true;
end;
end.