Delphi控制编辑类控件不能粘贴
来源:互联网 发布:软件开发前端和后端 编辑:程序博客网 时间:2024/06/13 08:35
在一些C/S软件和登录网站输入账号密码时经常只能进行输入,而不让用户直接粘贴,防止上次用户登录账号没清除,下一个用户直接粘贴该账号而导致账号信息泄露,刚好在公司开发中要实现该功能,下面记录下在Delphi中实现该功能的方法。粘贴主要是利用了windows的剪贴板功能,因此清除剪贴板中内容即可实现。
打开Delphi,新建一个应用程序,在窗体上放置2个Edit控件和一个popupmenu控件。窗体文件和源码如下:
object Form1: TForm1
Left = 333
Top = 327
Width = 328
Height = 199
Caption = '禁用粘贴功能'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object edt1: TEdit
Left = 64
Top = 32
Width = 121
Height = 21
PopupMenu = pm1
TabOrder = 0
OnKeyDown = edt1KeyDown
end
object edt2: TEdit
Left = 64
Top = 72
Width = 121
Height = 21
TabOrder = 1
OnKeyDown = edt2KeyDown
end
object pm1: TPopupMenu
Left = 216
Top = 64
end
end
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus;
type
TForm1 = class(TForm)
pm1: TPopupMenu;
edt1: TEdit;
edt2: TEdit;
procedure edt1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure edt2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses clipbrd;
procedure TForm1.edt1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key in [86..118]) and (ssCtrl in Shift) then
edt1.ReadOnly:=True
else
edt1.ReadOnly:=False;
end;
procedure TForm1.edt2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key in [86..118]) and (ssCtrl in Shift) then
begin
if clipboard.HasFormat(CF_Text) then
clipboard.SetTextBuf('');
end;
end;
end.
方法一利用了控件的只读属性,而方法二直接给剪贴板内容设置为空串,这样其他地方也不能再使用该内容。效果如下:
屏蔽了右键菜单,只能输入不能粘贴内容。
- Delphi控制编辑类控件不能粘贴
- Delphi中webbrowser 不能复制粘贴
- jquery设置控件不能复制粘贴
- 模拟delphi编辑窗体操作控件。。。
- Delphi标准控件-编辑框(Edit)
- dev,buttonEdit控件,只能点击,不能编辑
- VC/MFC 使edit控件不能进行粘贴操作
- ueditor编辑文章时候,复制粘贴内容,原来的图片不能显示
- UEditor编辑文章时粘贴内容的时候导致原来的图片不能显示
- 编辑类控件
- 解决Delphi中webbrowser不能复制粘贴.打开paypal出错.直显HTML代码问题
- 编辑页面,修改charset后,css不能控制页面显示
- pb控制某些字段不能编辑的几种方式
- 不能进行复制粘贴
- 【UltraEdit】 不能复制粘贴
- UltraEdit 不能复制粘贴
- inpub 不能复制粘贴
- wps不能粘贴解决办法
- asp.net ADO.NET连接池使用与优化
- 将一个字符串数组的元素的顺序进行反转。
- 网络套接字学习以及聊天程序开发实例
- cmd for处理程序简介
- 求一个数组中的最大值。定义成函数
- Delphi控制编辑类控件不能粘贴
- js笔记
- Windows8与VMWare不兼容的解决方案
- 批处理之FOR语句祥解
- JAVA JSON 数据 大全
- POJ3211Washing Clothes
- 重装SQL Server 2005的一般方法:
- js获取对象位置的方法
- 今日关于HTML/CSS回顾